Gdb debugging php easily finds the currently executing code

little bottle
Release: 2023-04-06 11:32:02
forward
4296 people have browsed it

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--;
}
Copy after login

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
Copy after login

Then find the current php process

 

Then use gdb to debug

gdb -p 56571
Copy after login

Debugging

source /usr/local/src/php-7.2.9/.gdbinit
zbacktrace
Copy after login

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!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template