安装方法:
wget http://pecl.php.net/get/xhprof-0.9.x.tgz
cp xhprof-0.9.x.tgz /home/www/xhprof.tgz
tar zxvf /home/www/xhprof.tgz
cd xhprof/extension
phpize
./configure --enable-xhprof --with-php-config=/usr/bin/php-config
make && make install
vim /etc/php.ini
[xhprof]extension=xhprof.so;下面的这个地址是用来保存测量记录的目录,在页面输出测量得到的数据的时候,它会自动到这儿来找输出的文件。xhprof.output_dir=/tmp
service php-fpm restart
ok!
使用方法:
0) { bar($x - 1); }}// 在代码开头加上xhprof_enable();// xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);这个还可以分析cpu和内存使用情况// 你的程序foo();// 在代码结尾加上$xhprof_data = xhprof_disable();// xhprof的数据print_r($xhprof_data);//这里是xhprof的地址,echo出来直接复制地址访问可以查看报告$XHPROF_ROOT = realpath(dirname(__FILE__) .'/..');include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";// save raw data for this profiler run using default// implementation of iXHProfRuns.$xhprof_runs = new XHProfRuns_Default();// save the run under a namespace "xhprof_foo"$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");echo "---------------\n". "Assuming you have set up the http based UI for \n". "XHProf at some address, you can view run at \n". "http:///index.php?run=$run_id&source=xhprof_foo\n". "---------------\n";