首页 > Web开发 > 详细

php性能分析工具xhprof

时间:2014-02-18 10:34:47      阅读:372      评论:0      收藏:0      [点我收藏+]

安装方法:

wget http://pecl.php.net/get/xhprof-0.9.x.tgz

cp xhprof-0.9.x.tgz /home/www/xhprof.tgz

 

tar zxvf /home/www/xhprof.tgz

cd xhprof/extension

phpize

./configure --enable-xhprof --with-php-config=/usr/bin/php-config

make && make install

vim /etc/php.ini

[xhprof]
extension=xhprof.so
;下面的这个地址是用来保存测量记录的目录,在页面输出测量得到的数据的时候,它会自动到这儿来找输出的文件。
xhprof.output_dir=/tmp

 service php-fpm restart

ok!

使用方法:

bubuko.com,布布扣
<?php
//来自xhprof的例子
function bar($x) {
  if ($x > 0) {
    bar($x - 1);
  }
}


// 在代码开头加上
xhprof_enable();
// xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);这个还可以分析cpu和内存使用情况
// 你的程序
foo();

// 在代码结尾加上
$xhprof_data = xhprof_disable();

// xhprof的数据
print_r($xhprof_data);


//这里是xhprof的地址,echo出来直接复制地址访问可以查看报告
$XHPROF_ROOT = realpath(dirname(__FILE__) .‘/..‘);
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();

// save the run under a namespace "xhprof_foo"
$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://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n".
     "---------------\n";
bubuko.com,布布扣

php性能分析工具xhprof

原文:http://www.cnblogs.com/trying/p/3553161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!