Is there any runtime stack trace feature in PHP, by a given PID of it? (For whom also write Java, I mean jstack.)
I got few PHP background process that they are freeze once a while on some unknown lines. I can simply kill them all and restart but that don't prevent it happen again.
Is there a API able to spy the stack and tell? like the jstack utility provided from JDK?
You have a few options in terms of debugging unknown errors.
--enable-debug
.Xdebug
Use
gdb
to run the file that crashes and analyze the backtrace.--enable-debug
, a linux machine runningApache
, and a strong desire/ability to understand the way software works on a lower-level.gdb
withApache
:gdb /usr/lib/httpd
(gdb) run -X
... now, in your browser - access the page that crashes as normal and switch back to
gdb
:(gdb) backtrace
... the full backtrace will be printed
gdb
to run the script itself:(gdb) run /path/to/the/script.php
(gdb) backtrace
... the full backtrace will be printed
gdb
info, check out the quick-reference guide.Create a custom error handler that prints the stack trace when an error is thrown.
require('ErrorHandler.php');
to the top of your page and it should auto-register itself to handle any errors. Be sure to update the include-path to point to the actual file, of course.ErrorHandler.php: