您好,欢迎访问一九零五行业门户网

PHP 性能分析工具XHProf使用

来自: http://blog.csdn.net//clh604/article/details/21934453
当php程序逻辑执行很复杂的时候,可能会带来性能上的问题,为了有效的找到影响性能的代码,推荐大家使用php新能分析工具xhprof,该工具能有效的分析每段代码的执行情况,非常好用
1、安装配置php的扩展xhprof $ wget https://github.com/facebook/xhprof/tarball/master -o xhprof.tar.gz$ tar zxf xhprof.tar.gz$ cd facebook-xhprof-b8c76ac/extension/# phpize# ./configure --with-php-config=`/path/to/php-config`# make && make install# make test# vi /etc/php.d/xhprof.ini; 内容为:extension = xhprof.so; 注意:output_dir 必须存在且可写xhprof.output_dir = /tmp/xhpro然后重启apache服务# service php-fpm restart 或 service httpd restart
2、使用xhprof
// start profilingxhprof_enable();// run program....// stop profiler$xhprof_data = xhprof_disable();//// saving the xhprof run// using the default implementation of ixhprofruns.//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();// save the run under a namespace xhprof_foo.//// **note**:// by default save_run() will automatically generate a unique// run id for you. [you can override that behavior by passing// a run id (optional arg) to the save_run() method instead.]//$run_id = $xhprof_runs->save_run($xhprof_data, xhprof_foo);echo ---------------\n.assuming you have set up the http based ui for \n.xhprof at some address, you can view run at \n.http:///index.php?run=$run_id&source=xhprof_foo\n.---------------\n;如此一来,会在上面设定的xhprof.output_dir目录里生成名字类似49bafaa3a3f66.xhprof_foo的数据文件,可以很方便的通过web方式浏览效果:
3、展示输出结果 在 xhprof 源码包中提供了xhprof_html 和 xhprof_lib 两个文件夹,xhprof_lib是用于 php 开发,而xhprof_html用于显示 xhprof 分析结果的 web 界面,访问形式如下
http:///index.php?run=49bafaa3a3f66&source=xhprof_foo
其它类似信息

推荐信息