Skip to content

Instantly share code, notes, and snippets.

@dvessel
Forked from msonnabaum/xhprof_quick_and_dirty.md
Created February 11, 2013 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvessel/4757976 to your computer and use it in GitHub Desktop.
Save dvessel/4757976 to your computer and use it in GitHub Desktop.

Install XHProf

Pear

pear upgrade PEAR
pecl install xhprof-0.9.2

From source

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar -xzf xhprof-0.9.2.tgz && cd xhprof-0.9.2
phpize
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