D-e-e-b-u-g-g-i-n-g php
You can <?php echo $var; var_dump($var); print_r($var); ?> for the rest of ur life OR you could just use a real debugger
I’ve been trudging along for a while without a debugger. Var_dump’ing and echo’ing inbetween blobs of HTML or spewing out gunk on the command-line. Yuck. I’m ashamed of myself. And then one day I was struck down by a brilliant white light…
xDebug Debugger
A few years back i stumbled upon a php architect article on xDebug. Its avail thru pecl:
pecl install xdebug
Developed by that clever chap, Derick Rethans, xDebug makes debugging simple yet flexible. Great article on Zend Devzone if you haven’t read it already. Oh and if you’re using Zend Studio for Eclipse you’ll notice it takes a bit of jiggery pokery to get xDebug support from within the IDE.
See comment from dtaylor:
I think Zend hates xdebug… But the ZSE contains a full PDT (it has xdebug support). So, remove (move) the plugins/com.zend.php.debug*, then start the studion with “ZendStudio -clean”Hmm, there will be xdebug support in the PHP Debugger select..
It worked for me! FYI I make flagrant use of xdebug particularly for printing out stack traces and some additional super global data when testing web frontends.
Zend Debugger
Anyways, thats one way. An alternative is Zend Debugger which is natively supported by Zend Studio (including Eclipse PDT-based IDE) and doesn’t require any jiggery pokery. Download Zend Debugger. You’ll need to compile it as a zend extension and add it to ur php.ini. I think its available thru pecl too. A quickie help guide to debugging in Eclipse PDT
FYI I tried Zend for a while but had issues integrating the toolbar with the extension. Something about backwards incompatible changes to the debugging protocol since the last major release of Zend Debugger. Go figure
Debugger integration with Firefox
If you’re debugging in an external browser (viz. Mozilla Firefox) you’re going to want a handy way to switch on/off the debugger and profiling. For Zend Debugger you want the Zend Studio Toolbar (see note above regarding protocol issues). For xDebug you want the xDebug Helper extension.
Oh, and if you’re a Firebug fan. You’ll get a kick out of FirePHP. Not exactly a traditional debugger but if you’re more of a var_dump kind of guy this is for you.
Interpreting profile data
Both Zend Debugger and xDebug feature profiling and can thus write this data to disk (system tmp folder by default) on a per-request basis. The profile data is usually stored in cachegrind format which is NOT human-readable. Besides, you need a visual rendering of the data so you can easily tell which parts of the app consume the most time and energy. Answer: KCacheGrind.See screenshots here
If you’re running Linux and KDE happens to be you’re desktop then KCacheGrind is you’re baby (its open sauce… duh). Gnome users can install the KDE libs and get a half-decent user experience. Mac users can fudge it further by running KCacheGrind under X11. This is a bit easier when installed via macports. And for winblows users… well i dunno and i don’t particularly care. You should upgrade to Mac/Linux anyhows ![]()
For those foreign OSes that don’t wish to be polluted by KDE libs you can try webgrind (it’s free)
I’m running webgrind myself. Its very pretty and simple to use. By default it processes and displays the latest cachegrind file from your system’s tmp dir. Where is your temp dir you ask?
php -r "echo sys_get_temp_dir().\"\n\";"
Caution! Achtung baby! Since webgrind is a php app dont forget to switch off profiling when using webgrind via your web browser! I learnt the hard way and brought my desktop to its knees :/
Any OS
Well, almost any. AFAIK everything mentioned in this post should work in Windows, Mac OS X and Linux. I’ve tried this all on OS X Leopard, with little hassle. I use macports btw
I know it isn’t a very detailed post but heck if you follow some of those links and poke around you’ll surely find a combo you’ll grow to love and evangelize. Happy d-e-b-u-g-g-i-n-g !
3 years ago