Xdebug , Webgrind installation Xampp

Xdebug is awesome debugging extension available for PHP. Developer have to print data to screen using var_dump or echo to debug application. If application is huge it has to be multiple times to find the cause of error. Xdebug makes it easy to debug PHP application and in my view it is major coding standard for PHP developers.

Not just debugging xdebug also useful for profiling PHP application. It produces files that are necessary for profiling tools to display each function and its cost. Profiler tools such as KCacheGrind or WinCacheGrind use these files to visually show all data.

Installing Xdebug 

Download latest version of xdebug from here. For Xampp use 32 bit NTS version. example file php_xdebug-2.2.3-5.4-vc9.dll. Copy this to you \xampp\php\ext\ folder. and enable xdebug in php.ini using below lines of code.

zend_extension = "C:\xampp\php\ext\php_xdebug-2.2.3-5.4-vc9.dll"

If you use netbeans IDE for development , I recommend enabling remote debugging. Copy paste below into php.ini

xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = ""

Installing Webgrind

Download webgrind from here. Unzip it to any folder in document root. for example “..\xampp\htdocs\webgrind” .  Add below lines to you php.ini

xdebug.profiler_enable = 1
xdebug.profiler_output_name = "xdebug.out.%t"
xdebug.profiler_output_dir = "C:\xampp\tmp"
xdebug.profiler_enable_trigger = 1

You can see profiling by accessing your Webgrind folder . for ex: http://localhost/webgrind . You can click update to see profiling. But when you click the show call graph , it is likely you may see broken image. That is because you have to install 2 more things for that to work.

Install python from here.

Install Graphviz from here.

Now add these changes in config files of webgrind.

edit “\webgrind\config.php”

static $pythonExecutable = 'C:\Python33\python.exe';
static $dotExecutable = 'C:\Graphviz2.34\bin\dot.exe';

And then a small change in index.php. On line 151 replace library/gprof2dot.py with absolute path of file. so line becomes something like

shell_exec(Webgrind_Config::$pythonExecutable.' C:/xampp/htdocs/webgrind/library/gprof2dot.py -n '.$showFraction.' -f callgrind '.Webgrind_Config::xdebugOutputDir().''.$dataFile.' | '.Webgrind_Config::$dotExecutable.' -Tpng -o ' . $filename);

Now you can see call graph when you click “show call graph”.