Last updated April 14, 2015. Created on October 19, 2010.
Edited by webchick, joshtaylor, joelpittet, Ron Williams. Log in to edit this page.

XHProf is a utility for profiling PHP. Unlike Xdebug profiling, it profiles both CPU cycles and memory usage (Xdebug 2.0.0RC4 and later only provides memory usage information in function traces).


Figure out where your php.ini file is:

php -i | grep php.ini

XHProf Install

The following are the setup instructions for various platforms.
Originally from the contributor task profiling documentation:

Acquia Dev Desktop

There is already an in the DevDesktop extensions folder.

Edit your php.ini file, which should be something like /Applications/DevDesktop/php5_5/bin/php.ini.

Uncomment (Enable)

Add the output directory (the kit assumes this is the output directory)


Make sure you add your PHP to your $PATH
Edit your .bash_profile and add the following:

export PATH=/Applications/acquia-drupal/php5_3/bin:$PATH


See also: Installing XHProf for MAMP on Mac OS 10.6 (Snow Leopard) if you are using MAMP.

(Get the from but note that the xhprof.output_dir is different in these instructions.)

1) Copy to /Applications/MAMP/bin/php/php5.x.x/lib/php/extensions/no-debug-non-zts-200xxxxx/ (replacing x with your PHP version and xxxxx with the date on the existing extensions dir)

2) Add the following lines to your php.ini (Open MAMP click on File → Edit Template → PHP → PHP 5.x.x php.ini)

Mac (with Homebrew PHP)

brew install php54-xhprof (or whatever PHP version you're running).

Then edit your ext-xhprof.ini at e.g. /usr/local/etc/php/5.4/conf.d/ext-xhprof.ini to add:



Use pecl: pear channel-update
pecl install xhprof
pecl install channel://
apt-get install php5-dev
Add the xhprof config:
to /etc/php5/conf.d/xhprof.ini



These are useful if you want a different version of XHProf, e.g. 0.9.4.

  1. Download from PECL - pecl d xhprof-0.9.4. Confirm this is the latest version of xhprof before downloading
  2. Extract the xhprof PECL package - tar xzf xhprof-0.9.4.tgz
  3. Compile the xhprof package.
    cd xhprof-0.9.4/extension
    sudo make install

Verify XHProf is installed

To verify that xhprof is installed and working, run the following:

php -i | grep xhprof

You should see output similar to the following:

xhprof => 0.9.4

If not, check the installation instructions above (make sure to restart your web server!) accordingly. Make note of the version number for later.

Capturing and viewing XHProf output

XHProf module

The easiest way is to get up and running is to download and enable the XHProf module.

drush dl XHProf
drush en XHProf -y

Turn on and configure page profiling at admin/config/development/xhprof.

XHProf settings page

After saving the form, all pages will have a small "XHProf output" link in the page footer. Click it to view the output of that page, or go to admin/reports/xhprof for a list of all reports.

XHProf output

Unfortunately, the Drupal implementation of XHProf lacks the ability to view the 'callgraph' - this is a really useful chart of how the functions all relate to each other and helps to visualize what is going on.

Capturing and viewing native XHProf output

Manually download and extract XHProf (make sure the version matches the PHP ini output above).


pecl d xhprof-0.9.4
sudo pecl install xhprof-beta (if that doesn't work try just xhprof)
tar xzf xhprof-0.9.4.tgz

To access the callgraphs, go to http://[xhprof.loc]/xhprof_html/index.php (or whatever you set up for your localhost of XHProf in step x) and click on any of the report numbers. There will be a link near the top that reads 'View Full Callgraph'. If you click on this and you get an error (instead of a nice chart) you probably need to install Graphviz. You can grab the .pkg for the appropriate version for your OS at Click through the installation and then the graphs should work.

Looking for support? Visit the forums, or join #drupal-support in IRC.


Mixologic’s picture

I had to run phpize before ./configure.

jpstrikesback’s picture

To install the extension in MAMP on Snow Leopard I needed to:

- get the MAMP components (src for all)
- create the include/php folders inside /Applications/MAMP/bin/php5.[x]/
- copy php src into /Applications/MAMP/bin/php5.[x]/include/php
- run configure on the php source before I could phpize to build the extension as detailed here

cd /Applications/MAMP/bin/php5.[x]/include/php
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
./configure --with-config-file-path=/Applications/MAMP/bin/php5.[x]/bin/php-config

- then I could run phpize & make :)

erikwebb’s picture

Thanks, added phpize to the original post.

wesku’s picture

The Devel module now integrates with XHProf. You should use it instead of steps 4-6.

erikwebb’s picture

Agreed, thanks for the reminder.

vwX’s picture

To install via pecl

1. Update pear using "sudo pear update pear"
2. Install using "sudo pecl install channel://"

Have fun and check my Drupal Profile:

Elijah Lynn’s picture

I found this resource very valuable in setting up xhprof with Devel on Ubuntu 13.04.

The Future is Open!

manish9a9’s picture

How can I enhance the performance using XHprof report ?? or is there any way to enhance the performance ??