1. 编译安装
wget http://pecl.php.net/get/xhprof-0.9.3.tgz
tar zxvf xhprof-0.9.3.tgz
cd xhprof-0.9.3/extension/
sudo phpize
./configure --with-php-config=/usr/local/php/bin/php-config
sudo make
sudo make install
2. 配置 php.ini[xhprof]
extension=xhprof.so;
xhprof.output_dir=/tmp/xhprof
3. 重启web server
4. 加入代码
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
$xhprof_data = xhprof_disable();
$XHPROF_ROOT = "/var/www/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");//run_id当前请求生成的文件ID
echo "http://localhost/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";