Installation:
PECL Installation
As of Xdebug 0.9.0 you can install Xdebug through PEAR/PECL. This only works with with PEAR version 0.9.1-dev or higher and some UNIX. And of course on Mac.
Installing with PEAR/PECL is as easy as:
# pecl install xdebug
but you still need to add the correct line to your php.ini: (don't forget to change the path and filename to the correct one — but make sure you use the full path)
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so; (the full path in my PC)
Don't forget to restart Apache.
Note: You should ignore any prompts to add "extension=xdebug.so" to php.ini — this will cause problems.
To verify if you have Xdebug loaded on your machine.
Create a file to run phpinfo().
You would see something like this:
In the case you use "extension=xdebug.so", you will get a warning message in phpinfo().
Here we go. More installation methods, please visit Xdebug documentation .
------------------------------------------------------------------------------------------------------------
Basic Features
It says Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types and places limits on the amount of array elements/object properties, maximum depth and string lengths in the document.
Let's try the popular function var_dump() we use for debug.
<?php
header( "X-Test", "Testing" );
setcookie( "TestCookie", "test-value" );
var_dump( xdebug_get_headers() );
?>
Wow... very ugly, nothing different on my page, where are the colors?
Don't worry, check this:
By default Xdebug overloads var_dump() with its own improved version for displaying variables when the html_errors php.ini setting is set to 1. In case you do not want that, you can set this setting to 0, but check first if it's not smarter to turn off html_errors.
AHa, it's html_errors setting in php.ini. You could either change it in php.ini (restart Apache) or just add a line in your codes.
<?php
ini_set('html_errors', 1);
?>
Let's check this time:
Looks better now :)
Let's try this function void xdebug_debug_zval( [string varname [, ...]] ). This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. This function is implemented differently from PHP's debug_zval_dump() function in order to work around the problems that that function has because the variable itself is actually passed to the function.
<?php
$a = array(1, 2, 3);
$b =& $a;
$c =& $a[2];
xdebug_debug_zval('a');
?>
Pretty clear. No need to explain I think :) Wait, how about errors? Let's leave the function blank.
<?php
$a = array(1, 2, 3);
$b =& $a;
$c =& $a[2];
xdebug_debug_zval();
?>
No error shows? Is is the php setting again? Let's have a try.
<?php
ini_set('display_errors', 1);
?>
There we go. Looks cool and more understandable, isn't it?
Conclusion
1. Use full path when you edit zend_extension in php.ini ;
2. Turn on display_errors and html_errors in php.ini when debug mode.
Above all, some simple instructions for installation and basic usages. Please feel free to leave comments or email me if you have any question or find mistake in the article. Please visit the Xdebug site for more information.