Posts

Showing posts from February, 2012

How to dump PHP stack from gdb

The case: Php-based applications running on a linux server, be it under httpd or php-cgi process One of the applications misbehave, i.e. page never displayed until timeout Timeout mechanism doesn't work or we're unable to pinpoint the problem from the timeout message written on the logfile We would like to dump PHP stack traces from a running PHP script. Required tool: xdebug, gdb. Using standard xdebug functionality, debugging is only possible when php debugging explicitly initiated (eclipse/phpstorm must be running and the page is requested with debugging key activated). Just in time debugging in xdebug means debug when an error occured, which is not always the case. Remote_autostart means to debug in every time a php page is requested, which is an overkill in my opinion. Procedure : obtain list of pids from processes we're interested in ( ps auxw | grep httpd ) guess which pid (or iterate pids) run gdb, attach to the pid (gdb --pid= nn ) run this gdb scrip