function bar($x) { if ($x > 0) { bar($x - 1); } } function foo() { $i = 0; for ($idx = 0; $idx < 5; $idx++) { bar($idx); $i += strlen($idx); } return $i; } xhprof_sample_enable(); $i = 0; while ($i < 300) { if (rand(0, 99) > 50) { usleep(10000); ++$i; } foo(); bar(50); for ($j = 0; $j < 1000; ++$j) { $ret = str_replace('a', 'a', $j > 500 ? 'b' : 'bbbb'); } } echo $ret; $xhprof_data = xhprof_sample_disable(); file_put_contents(__DIR__ . '/' . PHP_VERSION . '-sample-' . date('His') . '.out', var_export($xhprof_data, true));
<?php if (function_exists('xhprof_sample_enable')) { ini_set('xhprof.sampling_interval', 50000); ini_set('xhprof.sampling_depth', 1); xhprof_sample_enable(); register_shutdown_function(function () { $xhProfData = xhprof_sample_disable(); include_once '/opt/xhprof/xhprof_lib/utils/xhprof_lib.php'; include_once '/opt/xhprof/xhprof_lib/utils/xhprof_runs.php'; $xhProf = new XHProfRuns_Default(); $runId = time(); $runName = rand(10000000, 99999999); $xhProf->save_run($xhProfData, $runName, $runId); }); }