Find php performance bottlenecks (xhprof)

Installation of xhprof

cd ~
git clone https://github.com/longxinH/xhprof

Install

cd xhprof/extension//usr/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --enable-xhprof
 make && make install

Modify the php.ini file

/usr/local/php/bin/php -i | grep php.ini //find php.ini file location
Add the /etc/php.inifollowing configuration in

[xhprof]
extension=xhprof.so
xhprof.output_dir=/data/www/xhprof/save_output_dir //该目录自由定义即可,用来保存xhprof生成的源文件
After saving, restartphp-fpm
 pkill php
/usr/local/php/sbin/php-fpm

Move the relevant files into the project root directory

//切换到下载的 xhprof 目录
cp -r xhprof/xhprof_html  ROOT_PATH/
cp -r xhprof/xhprof_lib ROOT_PATH/

How to use (modified in the index.php entry file)

xhprof_enable();

//The code you need to analyze

$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" );
//Save the run_id or output it with the code

View data
访问$host_url/xhprof_html/index.php来查看结果

View the graphical results

report an error

failed to execute cmd:" dot -Tpng". stderr:sh: dot:command not found
//解决方案
yum install graphviz

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856880&siteId=291194637