PHP性能监控软件XHProf的安装和使用(原创)

PHP性能监控软件XHProf的安装和使用(原创)
作者:余超 EMAIL:[email protected]

XHProf是facebook开源出来的一个php轻量级的性能分析工具,跟Xdebug类似。相对于XDebug来说配置更简单、更轻量级、更可控。
环境:linux+php+apache
一、安装XHProf
//下载到任意目录
[yuchao@yuchao-Latitude-E5410 dev]$wget http://pecl.php.net/get/xhprof-0.9.2.tgz  
//解压文件
[yuchao@yuchao-Latitude-E5410 dev]$tar zxf xhprof-0.9.2.tgz  
//进入解压后的文件夹
[yuchao@yuchao-Latitude-E5410 dev]$cd xhprof-0.9.2  
//拷贝xhprof_html xhprof_lib这两个文件夹到您的webroot目录,笔者的是/opt/lampp/htdocs
[yuchao@yuchao-Latitude-E5410 dev]$cp -r xhprof_html xhprof_lib /opt/lampp/htdocs/xhprof
//进入extension文件夹
[yuchao@yuchao-Latitude-E5410 dev]$cd extension
//执行phpize(笔者的phpize在/user/local/php/bin/phpize)
/user/local/php/bin/phpize
[yuchao@yuchao-Latitude-E5410 extension]$pwd
/home/yuchao/dev/xhprof-0.9.2/extension
[yuchao@yuchao-Latitude-E5410 extension]$phpize
[yuchao@yuchao-Latitude-E5410 extension]$ls
acinclude.m4    config.guess  config.m4      configure     libtool             Makefile.global   modules        xhprof.c
aclocal.m4      config.h      config.nice    configure.in  ltmain.sh           Makefile.objects  php_xhprof.h   xhprof.la
autom4te.cache  config.h.in   config.status  include       Makefile            missing           run-tests.php  xhprof.lo
build           config.log    config.sub     install-sh    Makefile.fragments  mkinstalldirs     tests
[yuchao@yuchao-Latitude-E5410 extension]$
[yuchao@yuchao-Latitude-E5410 dev]$./configure
[yuchao@yuchao-Latitude-E5410 dev]$make
[yuchao@yuchao-Latitude-E5410 dev]$make test
[yuchao@yuchao-Latitude-E5410 dev]$sudo make install
XHProf安装完毕你将会看见编译生成的/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xhprof.so模块
接下来我们需要配置php.ini,使php能加载XHProf编译后的xhprof.so模块,在php.ini中加入以下
[xhprof]
extension=xhprof.so
xhprof.output_dir=/opt/lampp/var/xhprof/


说明:xhprof.output_dir指的是xhprof分析结果存放的目录

现在我们开始测试:

examples目录下面有一个sample.php,


然后运行http://localhost/xhprof/examples/sample.php,将会在/opt/lampp/var/xhprof/下生成分析日志

4e6049216b797.xhprof_foo文件名中“4e6049216b797”为标识也就是传说中的id是变化的,“xhprof_foo”是文件后缀。
查看这条分析后的数据

比如刚刚生成的数据日志,我们通过url地址访问地址是http://localhost/xhprof_html/index.php?run=4e6049216b797&source=xhprof_foo 


这样你就会看见统计后的数据了,


当然也有图形化的界面,请自己Google之。


发布了46 篇原创文章 · 获赞 5 · 访问量 15万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章