How do I track php file execution through the console?

Asked

Viewed 294 times

0

update: actually my problem had nothing to do with this snippet from blockquote down there. I learned how to debug PHP, and I found several errors, but I’m not even going to enter here in each of them because it’s not the case... So even though I solved it differently, Guilherme’s comments and response helped me to understand some concepts, and how I think it can help other users, I decided not to remove the question and accept the answer.

-.-

Update: I found the problem, which is in this excerpt:

 <blockquote>
        <strong> <em>RECURSO DE REVISTA. [...] RESCISÃO DO CONTRATO DE TRABALHO - NULIDADE - AUSÊNCIA DE ASSISTÊNCIA SINDICAL.
        O objetivo da assistência sindical no pedido de demissão decorre da consagração do princípio da
        irrenunciabilidade dos direitos trabalhistas. Retrata o art. 477, § 1º, da CLT, norma cogente, que condiciona
        o pedido de demissão e a quitação do contrato de trabalho firmado pelo empregado cuja relação jurídica vigorou
        por mais de um ano, à assistência perante o Sindicato. Nesse sentido, a formalidade determinada pela norma, se
        não cumprida, torna nulo o ato. Incumbe ao empregador o cumprimento da formalidade prevista no art. 477, § 1º,
        da CLT, sob pena de não se convalidar o pedido de demissão, quando não houver a homologação, nos
        termos previstos na norma. Precedentes. Recurso de revista conhecido e provido. [...]</em></strong> (TST   PROCESSO Nº
        TST-RR-256-42.2010.5.02.0088, 6ª Turma, Relatora Desembargadora Convocada CILENE FERREIRA AMARO SANTOS,
        Data de Julgamento: 10/12/2014 - grifos nossos)
    </blockquote>

And the problem seems to be inside the text itself, I thought it was the use of brackets, but I think it’s not even, I tried to escape with \ and it didn’t work.

In fact, this other part is also giving the same problem (I have tested only one part, without the other, and gives the same problem):

<p>
            <?php echo $motivdesligjust; ?>
            <?php echo "<br>"; ?>
        </p>
        <p>
            <?php echo $motivdesligind; ?>
            </p>

I can’t call variables inside tags <p></p>?

/update

I’m having a problem here in running a php file, which uses include to include other files, and I can’t figure out the cause. It seems to be an infinite loop, but I’m not using for, while, nothing, just call the variables escaping the html, and use a if or another...

The file keeps running in the browser and not for more, there is the message "Waiting for localhost", and after that no other php file can run before I reset phpstorm.

So I was wondering if you have any commands for me to follow the execution, and why it keeps running in this infinite loop.

It is a strange mistake because are several files included by include, and if I remove the first 3 for example, it works, and the same happens if I leave only the first three, but I’ve already reviewed the files and I can’t find the problem.

  • Instead of include try include_once and see if it solves

  • I’ve tried, and with require tbm :/ @Guilhermenascimento

  • require only change the type of error issued, the _once prevents adding more than once. If it is not the include then it can be a recursive function

  • I think it is some problem with the included files, in these files I do not put header anything, already starts with <p>Título</p>... you think it might be like a tag without closure, or it might have something to do with the php I’m escaping into HTML... You know if there’s a way to access a log..?

  • Gustavo usually when entering an infinite loop is not generated log until the process is finished, the only types of errors that I believe are possible to capture are the markup error and the end of execution. This is due to the synchronous and non-synchronically occurring process of PHP. However maybe there is a debugging structure similar to C/C++ compilers like GCC for example, that when run in DEBUG it is possible to do a "backtrace" and if the application is terminated prematurely then you would have the log (however it would not be something easy to read). I’ll look into

  • Okay, thanks! I was thinking about trying debug-backtrace, but I don’t even know how to...

  • Gustavo debug_backtrace is more for use inside the execution, which may work, but will have to an autoload method maybe, because if not the whole process will be manual, before you can get any relevant result.

  • @Guilhermenascimento, I installed Composer, but I couldn’t install the monolog (today it’s complicated pqp :/), but I decided to put everything in one file and found where the error was. I edited the question, take a look... Thanks, hug.

Show 3 more comments

1 answer

2


As this question in Soen there are some tools for this, such as:

monolog

Installing with Composer:

$ composer require monolog/monolog

Basic example of use:

<?php

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('name');
$log->pushHandler(new StreamHandler('pasta/seu-arquivo-de-log.log', Logger::WARNING));

// Adiciona gravações para o log
$log->addWarning('Foo');
$log->addError('Bar');

phptrace

(i’m not sure, but I think it only works with FPM, apache2handler which is more common in windows with apache might not work)

  1. Extract the extension:

    tar -zxf phptrace-{version}.tar.gz
    cd phptrace-{version}
    
  2. Compile the extension

    cd extension
    {php_bin_dir}/phpize
    ./configure --with-php-config={php_bin_dir}/php-config
    make
    make install
    

    (in case it is windows and mingw will probably have to use mingw32-make)

  3. Copy the compiled extension to the php extension folder and edit php.ini

    extension=trace.so
    
  4. Compile the commandtool

    cd cmdtool
    make
    
  5. Testing if installation is ok:

    php -r 'for ($i = 0; $i < 100; $i++) usleep(10000);' & ./phptrace -p $!
    
  • Thanks man, I’ll try here! + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.