你的位置:首页 > 服务器类

一、安装xhprof

1.1、下载xhprof

下载地址1:https://github.com/longxinH/xhprof
或直接使用git:
git clone https://github.com/longxinH/xhprof

如果没有安装git,使用yum install git -y安装

下载地址2:wget https://soft.loveyan.com/web/xhprof/xhprof.tar.gz

1.2、解压

tar xzvf xhprof.tar.gz

1.3、编译安装

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

1.4、配置

vi /usr/local/webserver/php721/etc/php.ini
添加:
[xhprof]
extension = "xhprof.so"
xhprof.output_dir=/tmp/xhprof

创建/tmp/xhprof/目录:mkdir /tmp/xhprof

如果是以root用户操作的,注意把文件夹权限设置为web运行用户chown -R www:www /tmp/xhprof/ (www为本文测试使用的用户与和用户组名,根据你的实际情况修改)

1.5、查看xhprof是否正常加载

/usr/local/webserver/php721/bin/php -m|grep xhprof

重启php-fpm

/usr/local/webserver/php721/sbin/php7 restart

你也可以访问phpinfo页面查看是否已经加载xhprof

二、安装graphviz工具

 2.1、使用yum安装

yum install graphviz graphviz-devel libpng libpng-devel -y

2.2、编译安装

下载地址:http://www.graphviz.org/download/
下载当前最新版本
wget https://graphviz.gitlab.io/pub/graphviz/stable/SOURCES/graphviz.tar.gz

2.3、解压

tar xzvf graphviz.tar.gz

2.4、编译

cd graphviz-2.40.1/
./configure --with-png=yes
make
make install

三、配置实例及xhprof图形化web工具

3.1、到xhprof文件目录复制相关文件到站点目录

cp -r examples xhprof_html xhprof_lib /home/webroot/test/

3.2、运行实例查看效果

打开浏览器输入你的站点访问地址:http://url/examples/sample.php

你会得到例似http:///index.php?run=5b8fb1dc2c1ee&source=xhprof_foo的URL,如下图:

把得到的URL修改为你实际可访问的地址, http://your ip or domain/xhprof_html/index.php?run=5b8fb1dc2c1ee&source=xhprof_foo,即前面补全为你的站点访问地址,使用浏览器打开这个URL就可以看见运行的结果了,如下图:

如果你点击:[View Full Callgraph]出现failed to execute cmd " dot -Tpng"的错误,可能是你的php.ini配置中disable_functions那里禁用了proc_open函数,修改php.ini配置文件去掉这个限制就可以图形展示了,感兴趣的朋友可以自己配置一个玩玩。

  • 发表评论
  • 查看评论
【暂无评论!】

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。