Skip to content

Instantly share code, notes, and snippets.

@jpgreth
Forked from tallsam/xhprof_quick_and_dirty.md
Created November 12, 2013 09:12
Show Gist options
  • Select an option

  • Save jpgreth/7427864 to your computer and use it in GitHub Desktop.

Select an option

Save jpgreth/7427864 to your computer and use it in GitHub Desktop.

Install XHProf

Pear

sudo pear upgrade PEAR
sudo pecl install xhprof-0.9.2

From source

Need the patch to avoid https://bugs.php.net/bug.php?id=61674

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar -xzf xhprof-0.9.2.tgz && cd xhprof-0.9.2
wget https://github.com/facebook/xhprof/commit/a6bae51236.diff
patch -p1 < a6bae51236.diff
cd extension

phpize
./configure
make

sudo cp modules/xhprof.so $(php-config --extension-dir)/
echo "extension=xhprof.so" | sudo tee -a /etc/php5/conf.d/20-xhprof.ini
# Create an xhprof virtualhost now
wget https://raw.github.com/msonnabaum/xhprof-single-file/master/index.php -O /your/virtualhost/docroot/xhprof.php
sudo /etc/init.d/apache2 reload
php -i | grep xhprof

wget https://raw.github.com/msonnabaum/xhprof-single-file/master/index.php -O /your/project/path/xhprof.php

Drupal

Add the following to Drupal's index.php:

<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
register_shutdown_function(function() {
  $xhprof_data = xhprof_disable();
  $namespace = 'sitename';
  $filename = '/tmp/' . uniqid() . '.' . $namespace . '.xhprof';
  file_put_contents($filename, serialize($xhprof_data));
});

Load the site, and you should now see some .xhprof files in /tmp. You can check the output using the script you installed at the xhprof virtualhost's index.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment