下載xhprof
http://pecl.php.net/package/xhprof
解壓縮
tar ***.tgz
安裝:
pecl install xhprof....tgz
配置
[xhprof]
extension=xhprof.so
xhprof.output_dir=/work/code/xhprof
使用:
xhprof_enable();
//你需要分析的代碼
$xhprof_data = xhprof_disable();
include_once ROOT_PATH.'/xhprof_lib/utils/xhprof_lib.php';
include_once ROOT_PATH . '/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test");
//將run_id保存起來或者隨代碼一起輸出
查看:
xhprof_html 在tgz包中
訪問$host_url/xhprof_html/index.php?run=58d3b28b521f6&source=xhprof_test
來查看結果
或者:
進入xhprof.tgz解壓目錄
cd xhprof-2.2.0/xhprof_html
使用php原生服務器 執行
$ php -S 0.0.0.0:8000
瀏覽器打開: http://192.168.56.40:8000/
圖形化結果
點擊[View Full Callgraph]
可以看圖形化結果
報錯
failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found。
//解決方案
yum install graphviz
參考