centos6 安装xhprof扩展


首先配置yum源

追加CentOS 6.5的epel及remi源

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

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

检查已安装的php包

# yumlist--enablerepo=remi--enablerepo=remi-php56|grepphp

安装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

# yuminstall--enablerepo=remi--enablerepo=remi-php56php-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

优质内容筛选与推荐>>
1、10.18js本质
2、[BZOJ1642][Usaco2007 Nov]Milking Time 挤奶时间
3、理解Angular中的$scope
4、Objective-C介绍
5、如何将U盘转化成NTFS格式


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号