php 应用 cpu 100% 调试方法

找出进程占用cpu高的原因。

进程占用cpu高,一般是由于进程长时间占用cpu,又没有主动释放占用。如果想主动释放cpu,可以调用sleep。在写程序的时候,尤其要注意while 等循环的地方。

找出php进程在执行那段代码

$sudo gdb -p 10434
(gdb) print (char *)executor_globals.active_op_array->filename
$13 = 0x2924118 "/home/admin/gearman_manager/pecl-manager.php" (gdb) print executor_globals->current_execute_data->opline->lineno $14 = 55 (gdb) c Continuing. ^C Program received signal SIGINT, Interrupt. 0x00000031d32306d0 in sigprocmask () from /lib64/libc.so.6 (gdb) print executor_globals->current_execute_data->opline->lineno $15 = 71 (gdb) c Continuing. ^C Program received signal SIGINT, Interrupt. 0x00000000006250e1 in zend_hash_find () (gdb) print executor_globals->current_execute_data->opline->lineno $16 = 53 

如果对上面的命令有疑问,可以查看 当cpu飙升时,找出php中可能有问题的代码行
根据上面的信息,我们可以知道,cpu高时,正在执行/home/admin/gearman_manager/pecl-manager.php文件。并且正在执行53和71行附近的代码。

 

还可以通过strace进行调试

转载于:https://www.cnblogs.com/sidesky/p/4244758.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值