facebook php程序监控性能软件xhprof安装配置

xdebug部署线上服务,消耗太厉害,所以用xhprof 安装
安装前说明 我php装在/usr/local/php下,虚机建在/usr/local/www/uusnn.com.cn下
1.下载安装
<pre>    wget http://pecl.php.net/get/xhprof-0.9.2.tgz
   tar zxf xhprof-0.9.2.tgz
   cd xhprof-0.9.2
   cp -r xhprof_html xhprof_lib /usr/local/www/uusnn.com.cn
   cd extension
   /usr/local/php/bin/phpize
    ./configure
    make
    make install</pre>
2.php.ini配置
<pre>[xhprof]
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=/var/log/xhprof/</pre>
3.测试代码,用自带的这个简单的php函数

如果想知道cpu和内存使用情况可以这样写就行了
<pre><span style="color: #ff0000;">xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
</span></pre>
<pre>
< ?php
   // start profiling
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
   // run program
function bar($x) {
  if ($x > 0) {
    bar($x - 1);
  }
}

function foo() {
  for ($idx = 0; $idx < 2; $idx++) {
    bar($idx);
    $x = strlen("abc");
  }
}
foo();
   // stop profiler
   $xhprof_data = xhprof_disable();
   //
   // Saving the XHProf run
   // using the default implementation of iXHProfRuns.
   //
   include_once  "xhprof_lib/utils/xhprof_lib.php";
   include_once  "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://xhprof_html\index.php?run=$run_id&source=xhprof_foo\n".
   "---------------\n";
</pre>
4.写个文件看看他
现在执行上面的文件,可保存为xhprof.php
http://www.uusnn.com.cn/xhprof/xhprof.php
4d1b0c6fe2456.xhprof_foo 为生成的文件,是php的序列化数字
<pre>&lt; ?php
$html = file_get_contents('/var/log/xhprof/4d1b0c6fe2456.xhprof_foo');
print_r( unserialize($html));</pre>
&lt; 原创,转载请说明出处www.uusnn.com.cn&gt;
<!--more-->
4.打印结果
Array
(
[foo==&gt;bar] =&gt; Array
(
[ct] =&gt; 2
[wt] =&gt; 81
)

[foo==&gt;strlen] =&gt; Array
(
[ct] =&gt; 2
[wt] =&gt; 1
)

[bar==&gt;bar@1] =&gt; Array
(
[ct] =&gt; 1
[wt] =&gt; 1
)

[main()==&gt;foo] =&gt; Array
(
[ct] =&gt; 1
[wt] =&gt; 201
)

[main()==&gt;xhprof_disable] =&gt; Array
(
[ct] =&gt; 1
[wt] =&gt; 0
)

[main()] =&gt; Array
(
[ct] =&gt; 1
[wt] =&gt; 219
)

)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值