Herman J. Radtke III

Read more of my blog or subscribe to my feed.

PHP extension debugging hack

Written by Herman J. Radtke III on 28 Feb 2009

At work I maintain a handful of custom PHP extensions.  When someone reports a problem with one of the extensions, I want to fire up gdb right away and see exactly what is going on.  In order to do this, I build a custom php binary with debugging enabled.  I leave this binary inside my home directory so as not to affect my installed production php binary.  I should now be able to rebuild my custom extensions now with debugging enabled and start debugging.  But wait, the configure script rejects the flag. The problem is that my custom extensions are deployed as shared objects and use phpize to build outside of the php source directory.  The makefiles generated by phpize compile against my installed production php header files.  The configure script generated by phpize checks against these header files to see if debugging is turned on.  If it is not, then it does not let me compile my extension with debugging flags. The quick and dirty solution I found to this problem is to modify the php_config.h file commonly found in the /usr/local/include/php/main directory.  Change the ZEND_DEBUG flag from 0 to 1.  There are two defines, make sure to modify both of them.  Switch it back to 0 when done with the debug session. Happy hacking...