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 ./configuremake && make install、
增加配置php.ini
[xhprof]extension=xhprof.soxhprof.output_dir=/tmp
//
使用xhprof會在nginx下報502 Bad Gateway錯誤
我的運行環境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) 1.nginx配置nginx.conf
fastcgi_param PHP_VALUE "auto_prepend_file=/etc/config_home/inject.php"; 2.php配置:php.ini auto_prepend_file =/etc/config_home/inject.php 3. php檔案 //開啟xhprof xhprof_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_html 5.xhprof_lib 備忘說明 Incl. CPU (microsecs):包含內建函式 CPU 花費的時間,單位微秒 Excl. CPU (microsec):不包含內建函式 CPU 花費的時間,單位微秒 Incl. MemUse (bytes):包含內建函式所佔記憶體,單位位元組 Excl. MemUse (bytes):不包含內建函式所佔記憶體,單位位元組 Incl. PeakMemUse (bytes):包含內建函式所佔記憶體峰值,單位位元組 Excl. PeakMemUse (bytes):不包含內建函式所佔記憶體峰值,單位位元組