centos6 安装xhprof扩展

首先配置yum源

追加CentOS 6.5的epel及remi源

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

检查已安装的php包

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

安装php5.6

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit

php-pecl-xdebug php-pecl-xhprof

查看php版本

# php --version 或 php -v

安装php-fpm

# yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm

以上只是准备工作!!!

# wget http://pecl.php.net/get/xhprof-0.9.4.tgz

# tar zxvf xhprof-0.9.4.tgz

# cd xhprof-0.9.4

# whereis phpize

# /usr/bin/phpize #上一步得到的命令所在位置

如果报以下错误

Cannot find config.m4.

Make sure that you run '/usr/bin/phpize'in the top level source directory of the module

在当前目录下进入extension目录下:

# cd extension/

# ls config.m4 php_xhprof.h tests xhprof.c

# phpizeConfiguringfor:PHPApiVersion:20100412ZendModuleApiNo:20100525ZendExtensionApiNo:220100525

然后编译安装:

# whereis php-config #查找php-config的位置 # ./configure --with-php-config=/usr/bin/php-config #/usr/bin/php-config 上一步的结果 # make && make install

没报错就说明安装成功,然后就是在php.ini加入扩展

# vim /etc/php.ini

在文件中添加一句:

extension = xhprof.so

重启php-fpm生效

# service php-fpm restart

安装xhprof扩展已经完成

如何使用xhprof

将文件拷贝到网站目录里面,然后添加监控代码到统计文件中,这一步是引入文件

# mkdir -p /home/www/xhprof && cd /home/www/xhprof/

之前是在tmp目录下下载xhprof-0.9.4包
# cp -r /tmp/xhprof-0.9.4/xhprof_html/ ./
# cp -r /tmp/xhprof-0.9.4/examples/ ./# cp -r /tmp/xhprof-0.9.4/xhprof_lib/ ./# mkdir logs


项目中的使用方法(打点):
1.开始标志
xhprof_enable();

2.被包含的函数体,也是项目中需要检测的函数
function();

3.结束标志
$data = xhprof_disable(); $xhprof_root = "/home/wwwroot/xhprof"; include_once $xhprof_root."/xhprof_lib/utils/xhprof_lib.php"; include_once $xhprof_root."/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($data, "test");


访问路径:
xxx.xxx.xxx.xxx 代表服务器主机
http://xxx.xxx.xxx.xxx/xhprof/xhprof_html/index.php?run=$run_id&source=test

个人觉得打点到访问这个过程可以封装起来,方便使用

其中[View Full Callgraph]按钮可以查看耗时情况分布图,如果点击出现以下报错: Error: either we can not find profile data for run_id 58b393370e400 or the threshold 0.01 is too small or you do not have 'dot' image generation utility installed. 错误︰ 我们不能为 run_id 58b393370e400 找到配置文件数据或 0.01 阈值是太小或您没有安装的 '点' 图像生成实用程序。 xhprof绘制的是png图,绘图的dot拓展没装成功,也就是dot 不支持PNG # yum install -y graphviz 即可


 

 

 

 

 

 

 

 

wget http://pecl.php.net/get/xhprof-0.9.4.tgz tar zxvf xhprof-0.9.4.tgz cd xhprof-0.9.4 whereis phpize /usr/bin/phpize

转载于:https://www.cnblogs.com/cyj1733/p/6536472.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值