centos 下 xhprof 的安装与使用 - Go语言中文社区

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

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_33691817/article/details/91857492
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-07 16:17:37
  • 阅读 ( 784 )
  • 分类:Linux

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢