Sunday, May 13, 2012


Profiling PHP Applications on Apache Using Xdebug and Xdebugtoolkit

Your app is slow?You can take a real deep look into your application using the profiling options of Xdebug.
How To:

We will be using RHEL / CentOS as operating system for this tutorial. For more information about installing Xdebug, get it here.

1. Assuming that you have PEAR/PECL installed, get Xdebug by,

# pecl install xdebug

The command above will install the xdebug.so module to your php modules directory which is usually located at /usr/lib64/php/modules (part of distribution) or /usr/local/lib/php/modules (user installed).

2. Activate the xdebug module by adding the following entry to php.ini.

zend_extension = /path/to/xdebug.so or zend_extension = xdebug.so

Note:
 xdebug is a zend extension, DO NOT use "extension=xdebug.so". This will fail.

You can place the entry above to php.ini by doing any of the following:

# vi /etc/php.ini, copy and paste into a line within the config, then save (ESC + colon + wq)
Or, if your php configuration was installed using dependency structure (/etc/php.d), you can simply do the following,

# cd /etc/php.d
# vi xdebug.ini, copy and paste into a line within the config, then save (ESC + colon + wq)

To configure, you can use the sample below, and paste it after the "zend_extension" module entry.

Xdebug Automatic Mode:

xdebug.profiler_enable = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R

Xdebug Trigger Mode:

xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name => cachegrind.out.%t-%R

3. Restart apache for changes to take effect.

# /etc/init.d/httpd restart
  • Install Xdebugtoolkit
1. Assuming that you have subversion installed, get xdebugtoolkit

# svn co http://xdebugtoolkit.googlecode.com/svn/tags/0.1.4/xdebugtoolkit/ xdebugtoolkit

2. Make sure that you have installed all dependencies. For more information, go to xdebugtoolkit.

# yum install python
# yum install pygtk2
# yum install graphviz , this will install "dot" on /usr/bin/dot


  • Generate Cachegrind or Application Profile Data
For Xdebug Automatic Mode, just visit the URLs that you want profiled. In our case, we used QAs regression test to fully profile the application.

For Xdebug Trigger Mode, just append XDEBUG_PROFILE=1 after each URL.

e.g http://yourdomain.com/?XDEBUG_PROFILE=1
  • Generate Graphs
·         # cd /tmp
·         # /path/to/xdebugtoolkit/cg2dot.py yourcachegrindfile | /path/to/dot -T png -o /path/to/file.png

No comments:

Search About OpenSource

Google