views:

203

answers:

4
+1  Q: 

Debugging PHP

I've been using xdebug to debug and understand code in php projects for a while now, and have sometimes come into situations where it's been unclear what's going on inside of PHP.

Is it possible to set xdebug or gdb up so that i can trace into actual php builtin functions?

+3  A: 

I doubt it, xdebug is intended for tracing your PHP code, not the internals. The internals are assumed to be bug-free (which obviously they aren't sometimes, but that's beyond the scope of xdebug).

You can always look at the PHP source if you want to know what the built-in functions do, but that's sometimes pretty hairy. The PHP manual docs have always served me well enough when I want to know what they'll do.

dirtside
+2  A: 

If you are using a macosx, solaris or recent freebsd system you can throw a little dtrace at it. It can come in handy for those all too numerous "WTF is PHP doing?" moments.

Trey
a quick google turned up http://blogs.sun.com/bmc/entry/dtrace_and_php_demonstrated - if you have more pointers to get started, please post them
xkcd150
nothing specific, I wasn't aware of that link, thanks. I've had some problems where tracing all filesystem calls from php were enough. Specifically looking for fopens and flocks. Turns out PHP doesn't like include_once/require_once declarations (it's not a use (perl)/import (java) replacement like I was treating it). Too many referenced files would cause a death by flock.
Trey
Oh, this was a good resource. http://www.brendangregg.com/DTrace/dtrace_oneliners.txt
Trey
+1  A: 

You can use gdb to trace in to the C-level code, provided you have php compiled with debug symbols. Have a look here for a start:

http://derickrethans.nl/phps_segmentation_faults_gdbfu.php

troelskn
A: 

One way to test the output of the Zend engine, to peek inside at the opcodes, you can use Derick Rethan's VLD (Vulcan Logic Dissasembler), which also appears to be on PECL. Note: only works on *nix systems (see site for requirements).

Some examples of debugging these opcodes can be found on Sara Golemon's blog, in articles such as Understanding Opcodes and How long is a piece of string?.

ken
nice, i will have to try that out, too. thanks!
xkcd150