PHP头条
热点:

Xhprofphp性能测试用具用法小结


Xhprof php性能测试工具用法小结

            Xhprof 是facebook推出的轻量级的php性能分析工具,和Xdebug相比,XHProf更加易用和可控,尤其是生成流程图和调试数据对比的功能很好很强大。  下面简单介绍下Xhprof的安装及使用。

           1、安装

          可以从页面 下载相应版本及了解各个版本依赖条件。 安装前,先假设php的bin目录是:/usr/local/php/bin

[root@localhost extension]# ln -s /usr/local/php/bin/phpize /usr/bin/phpize
[root@localhost tool]# wget http://pecl.php.net/get/xhprof-0.9.2.tgz
[root@localhost tool]# tar -zxvf xhprof-0.9.2.tgz 
[root@localhost tool]# cd xhprof-0.9.2/extension/
[root@localhost tool]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@localhost tool]# make
[root@localhost tool]# make install

           通过上面的操作,如果运气不是非常糟糕的话,你应该看到类似这样的提示:Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

          进入到php扩展库目录/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ ,你将看到xhprof.so 共享库文件。

        2、配置

         在php.ini文件中,添加如下配置:

[xhprof]
extension=xhprof.so;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
;xhprof.output_dir=
xhprof.output_dir=/tmp/xhprof

        重启下php,就可以在使用xhprof了。

       3、拷贝文件

       把xhprof-0.9.2目录下的目录xhprof_html 和 xhprof_lib 下的所有文件拷贝到你网站的主目录下,假设网站主目录:/opt/wordpress

[root@localhost xhprof-0.9.2]# cp -R xhprof_* /opt/wordpress

       4、使用

       参考下面的解释说明:

save_run($data, "xhprof");
 
//查看运行结果的url
//run的值来源于save_run的返回值
//source值来源于save_run的第二个参数                                 
//www.abc.com 需要用自己的域名替换
echo "http://www.abc.com/xhprof_html/index.php?run=".$run_id."&source=xhprof";

      在浏览器中打开输出的url,及可看到相关的性能信息。

 

www.phpzy.comtrue/phprm/36498.htmlTechArticleXhprofphp性能测试用具用法小结 Xhprof php性能测试工具用法小结 Xhprof 是facebook推出的轻量级的php性能分析工具,和Xdebug相比,XHProf更加易用和可控,尤其是生成流程图和调试数据对比的功...

相关文章

PHP之友评论

今天推荐