Introduction 中文
Phptrace is a tracing and troubleshooting tool for PHP scripts. The information of php execute context and php function calls are fetched from PHP Runtime. It is very useful to locate blocking problems, heavy-load problems and tricky bugs both in the online environment and the development environment.
- Extracting the tarball
tar -zxf phptrace-<version>.tar.gz
cd phptrace-<version>
- Compile the PHP extension
cd phpext
phpize
./configure --with-php-config=/path/to/php-config
make
- Compile the command tool
cd cmdtool
make
- Install the php extension (phptrace.so) to the PHP extension directory.
make install
- Edit php.ini and restart the php process if needed.
extension=phptrace.so
phptrace.enabled=1
- Use the phptrace tool directly under the cmdtool directory.
cd cmdtool
./phptrace [options]
- Trace php function calls.
$ ./phptrace -p 2459 # phptrace -p <PID>
1417506346.727223 run(<Null>)
1417506346.727232 say($msg = "hello world")
1417506346.727241 sleep($seconds = "1")
1417506347.727341 sleep => 0 1.000100
1417506347.727354 say => hello world 1.000122
1417506347.727358 run => nil 1.000135
- Print the stack of function call.
$ ./phptrace -p 3130 -s # phptrace -p <PID> -s
phptrace 0.1 demo, published by infra webcore team
process id = 3130
script_filename = /home/xxx/opt/nginx/webapp/block.php
[0x7f27b9a99dc8] sleep /home/xxx/opt/nginx/webapp/block.php:6
[0x7f27b9a99d08] say /home/xxx/opt/nginx/webapp/block.php:3
[0x7f27b9a99c50] run /home/xxx/opt/nginx/webapp/block.php:10
- It can print call stack of executing php process, which is similar to pstack.
- It can trace php function callls, which is similar to strace.
- It cannot get performance summary of php scripts, which will be supported in the future.
- It can not debug php scripts.
- It is used to debug php program, which is similar to gdb.
- It cannot print call stack of executing php process.
- It cannot trace php function calls.
- It is used to get performance summary, which is similar to gprof.
- It cannot print call stack of executing php process.
- It cannot trace php function calls.
- It can print call stack only if some error occurs.
- It would hook many opcode handlers even you did not set the auto_trace flag in php.ini; it traces all the processes at the same time just without output. This is a big overhea d in production envirenment.
- It can not be enabled to trace without modifying the ini or the php script.
- Email: [email protected]
- QQ Group: 428631461