2018-5-30
一、安装
cd /usr/local/src
git clone https://github.com/yuanshuli11/xhprof.git
cd xhprof/extension/
/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config
make
make install
出现
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20151012/
表示编译成功
然后修改php.ini的配置
增加
[xhprof]
extension=xhprof.so
xhprof.output_dir=/data/www/xhprof/save_output_dir //需要保证已创建该目录
systemctl restart php-fpm 重启php
二、使用
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");
echo $run_id; //输出run_id 便于查看结果
然后访问 访问$host_url/xhprof_html/index.php?run={$run_id}&source=xhprof_test来查看结果 (需要先配置virtualhost 使目录xhprof目录可访问)
访问成功后,点击[View Full Callgraph]可以看图形化结果
若遇到
failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found。
则需要先安装graphviz
yum intall graphviz
完~