Is it possible to attach a debugger to a running PHP process?

I have a PHP script that we run every few minutes through a cron entry, and every now and then (about once a week) instead of ending normally, it stays running, eating up 100% of a CPU core (i'm assuming, looping infinitely)

Looking at the code and "thinking" about it, I can't find any reason for this to happen, but it does. So far, when I get 3 or more of those I kill them, and that solves the CPU issue, but I'd like to do something about this...

Is there any way to dump a process, or attach to it with a debugger so that I can know something, anything about what it's doing? (Just which PHP line it's on would be of huge help). I don't mind if the process dies when I dump, or anything.

This is a PHP script, running from the command line, in a CentOS 5.6 machine, and I'm a big noob when it comes to *nix, so if you can point me to some tutorial for dummies that'd be awesome.

Thank you! Daniel


There's no way I'm aware of to attach a debugger to a PHP process that hasn't specifically been prepared with a PHP debugging extension (such as xdebug). However, you may be able to make some guess as to what's going on using the more general-purpose utility strace , which can deliver a trace of the system calls being run by a process. This will only tell you what system calls are being executed, but this may be enough (depending on the context) to determine what's going on anyway.

链接地址: http://www.djcxy.com/p/9342.html

上一篇: 使用复杂的位掩码确定哪个位设置为某个日期

下一篇: 是否可以将调试器附加到正在运行的PHP进程?