In my previous post I briefly mentioned debugging a php process with gdb. In this post I am going to describe the steps and required tools to successfully get insights/stacktrace from a running PHP process.
First thing first, make sure you have install php5-dbg package. In this example I am using an Ubuntu box.
$ dpkg-query -l | grep php5-dbg
If not found install it first
$ sudo apt-get install php5-dbg
We also need a
.gdbinit file. Get it from here according to php version.
Now it's time to start gdb with the php process.
$ sudo gdb -p PID
At the point gdb will pause the program, you need to type
continue inside the gdb shell.
Wait for a while and then press Ctrl+C to get back to gdb shell.
Now source the
.gdbinit, I put it into my home directory.
> source ~/.gdbinit
zbacktrace to see actual backtrace from the underlying php program.
After getting the stacktrace detach the program from gdb and then quit, if you dont detach the program, gdb will kill it when you quit gdb.
> detach > q
You can check other commands available in the
This helped me today to get actual stacktrace of the php program instead of php interpreter calls that I got with
gdb is really an awesome sauce!