使用xhprof对php性能追踪分析

xhprof是php得高性能分析应用,以图形化的形式形象的展示出php项目的性能瓶颈与每个类或者模块在运行时的耗时,php程序员就可以对自己项目进行针对性的优化。
这里写图片描述
这里写图片描述

一、下载 xhprof-0.9.4

http://pecl.php.net/package/xhprof

tar -zxf xhprof-0.9.4.tgz
cd xhprof-0.9.4/extension/
which php-config
phpize
./configure --with-php-config=/usr/bin/php-config
make && make install

二、配置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=/usr/local/xhprof/xhprof_log

三、使用xhprof

存放日志

mkdir -p /usr/local/xhprof/xhprof_log


xhprof_lib/utils/xhprof_lib.php
xhprof_lib/utils/xhprof_runs.php

放到要检测的项目能访问的目录里,php代码需要加载这2个php

php代码:

xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

................这里是要被监控的代码块

$data = xhprof_disable();

include_once "xhprof_lib/utils/xhprof_lib.php";
include_once "xhprof_lib/utils/xhprof_runs.php";
$objXhprofRun = new XHProfRuns_Default();//数据会保存在php.ini中xhprof.output_dir设置的目录去中
$run_id = $objXhprofRun->save_run($data, "test");
var_dump($run_id);

把examples xhprof_html xhprof_lib三个目录放到/usr/local/xhprof里边
搭建apache 指向xhprof_html/index.php
访问自己的服务器,例如:
http://myxhprof.net/index.php?run=553a1c8fecda0&source=test

如无法访问查看目录权限
ps -axu| grep httpd
查看字进程的所有者
chown -R web:web xhprof_log

[View Full Callgraph]
需要安装graphviz图形绘制工具
http://www.graphviz.org/Download_linux_rhel.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值