Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Last active December 12, 2015 04:08
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save msonnabaum/4711730 to your computer and use it in GitHub Desktop.
Save msonnabaum/4711730 to your computer and use it in GitHub Desktop.

Install XHProf

Pear

pear upgrade PEAR
pecl install xhprof-0.9.2

MAMP

If you're on mamp:

  1. Feel shame
  2. Try getting the compiled extensions here: https://github.com/cam8001/php-xhprof-mamp

From source

git clone git://github.com/facebook/xhprof.git
cd xhprof/extension
phpize
./configure
make
cp modules/xhprof.so $(php-config --extension-dir)/

Add to 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. These can be viewed with a single page version of the original UI found here:

https://github.com/msonnabaum/xhprof-single-file

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