Debugging With Xdebug
Xdebug is an amazing extension for PHP. It makes debugging your websites and web applications much easier. Let's take a look some debug before install Xdebug.
First, let's use var_dump() on a variable that happens to be an array:
var_dump($response);
This produces the following output:
Now, let's cause a PHP Error (Notice the missing semicolon).
var_dump($response)
This produces the following output:
As you can see, the output of the previous examples can make debugging difficult. In the first example, the output is very difficult to read. If the array contained more elements, this could be nearly impossible to find the data that you require.
Now, let's look at these examples with xdebug installed.
var_dump($response);
Will now reproduce the following output:
array
'Response'
array
'TransactionReference'
array
'XpciVersion' (length=6)
'ResponseStatusCode' (length=1)
'ResponseStatusDescription' (length=7)
'Error'
array
'ErrorSeverity' (length=4)
'ErrorCode' (length=5)
'ErrorDescription' (length=61)
'ErrorLocation'
array
'ErrorLocationElementName' (length=37)
Now, let's cause a PHP Error again.
var_dump($response)
This now produces the following output:
| ( ! ) Parse error: syntax error, unexpected '}' in /usr/dev/workspace/ups_api/tests/time_in_transit_test.php on line 57 |
|---|
Installing Xdebug On Kubuntu 7.10:
These instructions are specifically written for Kubuntu 7.10 Gutsy Gibbon. However, they should work for any Linux distrobution as long as the php-pear package is installed.
First, let's install the php-pear package, if it is not already.
Now it's time to install xdebug.
Now we need to add the extension and some settings in the PHP configuration files. Open php.ini in your favorite text editor as root. I prefer vim, but any editor will do. Just add the lines below, you may have to modify the path to your xdebug extension.
; Add the following lines to configure xdebug
zend_extension=/usr/lib/php5/20060613/xdebug.so
; xdebug settings
xdebug.var_display_max_children = 128
xdebug.var_display_max_data = 1024
xdebug.var_display_max_depth = 16
It really that simple. Now you can easily debug your web sites and web applications. For more configuration options, view the xdebug documentation at http://xdebug.org/docs/.


