If you want to use XHProf, here’s the PHP code I use to record profiles. I put it in index.php, but you could rework it slightly and use auto_prepend_file in PHP configuration to profile all the things without changing your code.


// Enable profiling for this request.
if (function_exists(‘xhprof_enable’)) {

* Your code here

// Save profile and output a link to the profile viewer.
if (function_exists(‘xhprof_disable’)) {
$xhprof_data = xhprof_disable();

$XHPROF_ROOT = “/xhprof/”;
include_once $XHPROF_ROOT . “/xhprof_lib/utils/xhprof_lib.php”;
include_once $XHPROF_ROOT . “/xhprof_lib/utils/xhprof_runs.php”;

$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, “xhprof_testing”);

echo “<a href=’http://xhprof.dev/index.php?run={$run_id}&source=xhprof_testing‘>profile</a>\n”;

echo ‘<pre>’ . print_r($LOGALLTHEQUERIES, TRUE) . ‘</pre>’;

Leave a Reply