I finally got around to installing Xdebug on my development environment and have decided it is the best thing since sliced bread. Installation was a breeze and the information it provides when something has gone wrong is incredibly helpful during debugging. What I didn't know, and hope to help others by documenting it here, was the amount of configuration options Xdebug has. The base install has some irritating limitations that are easily addressed with a few simple lines in the php.ini file.
Overview
Let's take a step back and describe exactly what we're dealing with here. Xdebug is a PHP extension meaning it is self-contained in a dll file and all you have to do is tell php to use it. The same way you turn on the PHP GD-image or cURL libraries is the same way you enable Xdebug.
Xdebug comes into play whenever PHP decides it needs to output an error, warning, notice, etc and it does so automatically. Instead of the plain old PHP error saying that you have a syntax error on line 84 of script test.php Xdebug will give you a stack trace including memory allocation, function parameters, execution time, and so much more.
Here is an example output:

All that information could take some time to manually dump out to the screen. Most of the time you probably won't need it during debugging but when you do it's a godsend.
var_dump() is my go-to function when debugging and Xdebug even makes that easier to read with some formatting and highlighting assistance.

Install and Configure
To install Xdebug just follow these easy steps:
- Download the latest version of Xdebug from their site http://www.xdebug.org/.
- Drop the .dll into your PHP extensions directory - Usually /php/ext/
- Add this line to your php.ini file (Obviously replace the filename if your version is different than mine):
extension=php_xdebug-2.0.3-5.2.5.dll - Configure Xdebug
- Here is my list of optional configuration settings I have:
xdebug.collect_params=4
xdebug.var_display_max_depth=999
xdebug.dump.POST=*
xdebug.dump.GET=*
xdebug.show_local_vars=1 - collect_params = 4
- Displays the variables passed as arguments to certain functions
- Without this, only function calls are shown and no information about its arguments.
- More information can be found on their Stack Trace Page.
- var_display_max_depth=999
- gives me a complete, un-abridged, variable dump when using var_dump
- By default, Xdebug will only show a couple levels of nesting. I found this irritating as I wanted to see everything when I var_dumped something.
- POST and GET =*
- Dumps anything in either variable.
- I could spend an extra couple of seconds printing out these variables manually but with this option, they are always infront of me during an error. Very helpful.
- show_local_vars = 1
- Displays any variables accessable in scope of the faulting function or method.
- Displays any variables accessable in scope of the faulting function or method.
- Add these to the bottom of your PHP.ini file.
- http://xdebug.org/docs/
- Here is my list of optional configuration settings I have:
It's important to note that absolutely no configuration is required apart from requiring the Xdebug extension in php.ini. Things will function perfectly using their default configuration but after going through their documentation I found several things that I thought would be useful and wanted to explain how to use a few of them in this article.
If you have any problems, check out Xdebug's Installation Documentation or leave a comment here and I'll try my best to find an answer.
Also Checkout
The guys over at the Zend Developer Zone have written up a great series about installing, configuring, and using all the advanced features of Xdebug. You can find that here:
http://devzone.zend.com/article/2803-Introducing-xdebug



Comments
Tarique Sani on (7.2.2008 6:58 am) says
Ortzinator on (7.2.2008 3:27 pm) says
Joakim Nygård on (7.5.2008 6:48 am) says
Salimane Adjao Moustapha on (7.5.2008 9:03 pm) says
BrentNewland on (8.7.2009 9:05 pm) says