wget http://pecl.php.net/get/xhprof-0.9.4.tgz
tar -zxvf xhprof-0.9.4.tgz
cd xhprof-0.9.4
cd extension/
phpize
./configure
make && make install、
增加配置php.ini
[xhprof] extension=xhprof.so xhprof.output_dir=/tmp
//使用xhprof会在nginx下报502 Bad Gateway错误
1.nginx配置nginx.conf我的运行环境Yii + nginx +php5.4.25+centos
bug修复
xhprof_enable()
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
修改为:
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY)
fastcgi_param PHP_VALUE "auto_prepend_file=/etc/config_home/inject.php";2.php配置:php.iniauto_prepend_file =/etc/config_home/inject.php3. php文件//开启xhprofxhprof_enable(XHPROF_FLAGS_NO_BUILTINS|XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU);//在程序结束后收集数据register_shutdown_function(function() {$xhprof_data = xhprof_disable();include_once "/var/ms/public/xhprof_lib/utils/xhprof_lib.php";include_once "/var/ms/public/xhprof_lib/utils/xhprof_runs.php";$objXhprofRun = new XHProfRuns_Default();
// 第一个参数j是xhprof_disable()函数返回的运行信息// 第二个参数是自定义的命名空间字符串(任意字符串),// 返回运行ID,用这个ID查看相关的运行结果$run_id = $objXhprofRun->save_run($xhprof_data, "xhprof");//让数据收集程序在后台运行if (function_exists('fastcgi_finish_request')) {fastcgi_finish_request();}});
4.xhprof_html5.xhprof_lib备注说明Incl. CPU (microsecs):包含内部函数 CPU 花费的时间,单位微秒Excl. CPU (microsec):不包含内部函数 CPU 花费的时间,单位微秒Incl. MemUse (bytes):包含内部函数所占内存,单位字节Excl. MemUse (bytes):不包含内部函数所占内存,单位字节Incl. PeakMemUse (bytes):包含内部函数所占内存峰值,单位字节Excl. PeakMemUse (bytes):不包含内部函数所占内存峰值,单位字节