Profiling with Xdebug and Kcachegrind

Here you can find the instructions for installing Xdebug and Kcachegrind to profile and debug PHP applications.

Supposing that you’re using the penguin, with Debian or *buntu, there are a few steps ( very easy steps ) that you have to do in order to set up an environment which helps you on debugging PHP and profiling scripts.

First of all install the software:

1
2
3
sudo apt-get install php5-xdebug

sudo apt-get install kcachegrind

then modify your php.ini:

1
sudo gedit /etc/php5/apache2/php.ini

inserting these lines of code:

1
2
3
4
5
6
; Xdebug params
xdebug.remote_enable = On
xdebug.profiler_enable=1
xdebug.profiler_output_dir = "/var/benchmark/"
zend_extension="/usr/lib/php5/20060613+lfs/xdebug.so"
xdebug.auto_trace = On

Remember to change, obviously, the values for profiler_output_dir and zend_extension.

TIP: to get zend_extension value use:

1
locate xdebug.so

Then remember to give apache write premissions of the profiler output directory and restart it:

1
sudo /etc/init.d/apache2 restart

Now you can navigate your local applications and find generated files in the output directory: you need to open these files with Kcachegrind and… …profile them!


In the mood for some more reading?

...or check the archives.