背景:以前调试PHP如CPU100%发生在哪儿,用GDB,现在PHP自己带了一个PHPGDB,方便调试。
root@119.10.6.23:/data/codesdev/phpServer# php test.php
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0# ps aux|grep test.php
root 4071 1.3 1.5 350356 92040 pts/1 S+ 11:37 0:00 php test.php
cli方式执行php脚本,加入执行的进程号为4071。我们使用gdb命令来调试进程。
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0# gdb -p 4071
(gdb) print (char *)executor_globals.active_op_array->filename
$1 = 0x2ad61b4c8c48 "/data/codesdev/phpServer/test.php"
(gdb) print (char *)executor_globals.active_op_array->function_name
$2 = 0x2ad61b4c8d50 "test1"
(gdb) print executor_globals->current_execute_data->opline->lineno
$3 = 4
(gdb) print executor_globals->current_execute_data->opline->lineno
$4 = 4
很显然,他正在执行第四行的sleep方法。
如果上面的方法你感觉麻烦,那你可以使用.gdbinit文件。这个文件在php源码的根目录下。使用方法如下:
题外话:
从php5.6开始,php中集成了一个phpdbg的工具。可以像gdb调试c语言程序一样,调试php程序。感兴趣的话,可以打开下面的连接看看。
https://wiki.php.net/rfc/phpdbg
http://phpdbg.com/docs
来自:http://www.searchtb.com/2014/04/当cpu飙升时,找出php中可能有问题的代码行.html
————————————————————————————————————————————————————————————
phpdbg 作为一个交互式集成的调试器SAPI:
http://phpdbg.com/
Download:
https://codeload.github.com/krakjoe/phpdbg/legacy.zip/v0.4.0
Unzip:
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0/ext/krakjoe-phpdbg-cee9645#
http://phpdbg.com/docs
Installation
To install phpdbg, you must compile the source against your PHP installation sources, and enable the SAPI with the configure command.
cd /usr/src/php-src/sapi
git clone https://github.com/krakjoe/phpdbg
cd ../
./buildconf --force
./config.nice
make -j8
make install-phpdbg
phpdbg Felipe Pena, Joe Watkins, Bob Weinand
Command Line Options
The following switches are implemented (just like cli SAPI):
-n ignore php ini
-c search for php ini in path
-z load zend extension
-d define php ini entry
The following switches change the default behaviour of phpdbg:
-v disables quietness
-s enabled stepping
-e sets execution context
-b boring - disables use of colour on the console
-I ignore .phpdbginit (default init file)
-i override .phpgdbinit location (implies -I)
-O set oplog output file
-q do not print banner on startup
-r jump straight to run
-E enable step through eval()
Note: passing -rr will cause phpdbg to quit after execution, rather than returning to the console
root@119.10.6.23:/data/codesdev/phpServer# php test.php
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0# ps aux|grep test.php
root 4071 1.3 1.5 350356 92040 pts/1 S+ 11:37 0:00 php test.php
cli方式执行php脚本,加入执行的进程号为4071。我们使用gdb命令来调试进程。
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0# gdb -p 4071
(gdb) print (char *)executor_globals.active_op_array->filename
$1 = 0x2ad61b4c8c48 "/data/codesdev/phpServer/test.php"
(gdb) print (char *)executor_globals.active_op_array->function_name
$2 = 0x2ad61b4c8d50 "test1"
(gdb) print executor_globals->current_execute_data->opline->lineno
$3 = 4
(gdb) print executor_globals->current_execute_data->opline->lineno
$4 = 4
很显然,他正在执行第四行的sleep方法。
如果上面的方法你感觉麻烦,那你可以使用.gdbinit文件。这个文件在php源码的根目录下。使用方法如下:
题外话:
从php5.6开始,php中集成了一个phpdbg的工具。可以像gdb调试c语言程序一样,调试php程序。感兴趣的话,可以打开下面的连接看看。
https://wiki.php.net/rfc/phpdbg
http://phpdbg.com/docs
来自:http://www.searchtb.com/2014/04/当cpu飙升时,找出php中可能有问题的代码行.html
————————————————————————————————————————————————————————————
phpdbg 作为一个交互式集成的调试器SAPI:
http://phpdbg.com/
Download:
https://codeload.github.com/krakjoe/phpdbg/legacy.zip/v0.4.0
Unzip:
root@119.10.6.23:/data/software/lnmp1.1-full/php-5.6.0/ext/krakjoe-phpdbg-cee9645#
http://phpdbg.com/docs
Installation
To install phpdbg, you must compile the source against your PHP installation sources, and enable the SAPI with the configure command.
cd /usr/src/php-src/sapi
git clone https://github.com/krakjoe/phpdbg
cd ../
./buildconf --force
./config.nice
make -j8
make install-phpdbg
phpdbg Felipe Pena, Joe Watkins, Bob Weinand
Command Line Options
The following switches are implemented (just like cli SAPI):
-n ignore php ini
-c search for php ini in path
-z load zend extension
-d define php ini entry
The following switches change the default behaviour of phpdbg:
-v disables quietness
-s enabled stepping
-e sets execution context
-b boring - disables use of colour on the console
-I ignore .phpdbginit (default init file)
-i override .phpgdbinit location (implies -I)
-O set oplog output file
-q do not print banner on startup
-r jump straight to run
-E enable step through eval()
Note: passing -rr will cause phpdbg to quit after execution, rather than returning to the console
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/7544/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2014-10-4 11:46
评论列表