Home >Backend Development >PHP Tutorial >Gdb debugging php easily finds the currently executing code

Gdb debugging php easily finds the currently executing code

little bottle
little bottleforward
2019-04-25 17:52:044334browse

Suppose there is a php script online, and suddenly something goes wrong one day. It is not handled but the process does not exit. This situation may be due to abnormal sleep or an endless loop of code, but how do we locate it? What we want to know most at this time should be what this script is doing at this moment. This is useful if gdb zbacktrace is used.

First of all, write a test script test.php, and write a sleep function in it. You can also change it to an infinite loop.

<?phpfunction Mecho($i){ echo $i.PHP_EOL;
}$i = 20;while($i>0){if($i%2==0){
  Mecho($i);
}sleep(100000);$i--;
}

zbacktrace is available in the php source code package downloaded. My current environment is newly installed and the current php version is php7.2.9

Direct cli execution test.php

php test.php

Then find the current php process

 

Then use gdb to debug

gdb -p 56571

Debugging

source /usr/local/src/php-7.2.9/.gdbinit
zbacktrace

This At that time, I knew that the sleep function in line 11 of test.php caused the process to sleep.

Related tutorials: PHP video tutorial

The above is the detailed content of Gdb debugging php easily finds the currently executing code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete
Previous article:PHP PCRE regular analysisNext article:PHP PCRE regular analysis

Related articles

See more