centos 下 xhprof 的安装与使用

# <directory_for_htdocs>  -  web可访问的目录,比如/www/xhprof,对应xhprof.***.com

#<directory_for_storing_xhprof_runs>  - xhprof数据存放的目录,比如/www/xhprof/xhprof_data,需要有web用户写入的权限,比如web用户为www

chown -hR www /www/xhprof/xhprof_data


#安装 xhprof扩展

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

tar zxvf xhprof-0.9.2.tgz

cd xhprof-0.9.2

cp -r xhprof_html xhprof_lib <directory_for_htdocs> # 应用程序所在目录

cd extension

/usr/local/webserver/php/bin/phpize

./configure  --with-php-config=/usr/local/webserver/php/bin/php-config

make

make install


#配置php.ini,在extension附近加上

extension=xhprof.so

; 存放目录

xhprof.output_dir=<directory_for_storing_xhprof_runs>


#如果要图形话,需要安装dot


wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz

tar zxvf graphviz-2.24.0.tar.gz

cd graphviz-2.24.0

./configure

make

make install


#修改/etc/profile,加入dot的PATH

PATH="$PATH:/usr/local/bin/dot"

export PATH


#使用

#在php的头部加上,可以设置记录频率,比如记录万分之一

$xhprof_flag = mt_rand(1, 10000);

if ($xhprof_flag === 1) {

    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

}

#在代码页的底部加上


if ($xhprof_flag) {

    $xhprof_data = xhprof_disable();

    include_once "./xhprof_lib/utils/xhprof_lib.php";

    include_once "./xhprof_lib/utils/xhprof_runs.php";

    $xhprof_runs = new XHProfRuns_Default();

    $xhprof_runs->save_run($xhprof_data, 'xhprof',"index_".time());

}


#当有该php的访问时,会在<directory_for_storing_xhprof_runs>目录下生成类似index_1277956324.xhprof的记录文件


#使用类似 http://xhprof.***.com/xhprof_html/index.php?run=index_1277956324,就可以看到结果


转载于:https://my.oschina.net/surjur/blog/325130

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值