xhprof使用

 

一、下载安装

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

tar zxvf xhprof-0.9.3.tgz

cd xhprof-0.9.3/extension

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

make

make install

完成后会生成xhprof.so的文件

 

 

二、配置xhprof

创建xhprof文件夹用户存储xhprof生成的图片文件

mkdir -p /data/xhprof

vim /usr/local/webserver/php5.6/etc/php.ini

开启xhprof扩展

[xhprof]

extension=/usr/local/webserver/php5.6/lib/php/extensions/no-debug-non-zts-20131226/xhprof.so

xhprof.output_dir=/data/xhprof

重启php查看xhprof扩展是否开启

service php restart

[root@dongzi ~]# php -m|grep xhp

xhprof

 

三、编写php脚本测试

首先将xhprof的源码包里面的xhprof_html与xhprof_lib拷贝到运行系统的根目录

<?php

xhprof_enable();

////要测试的php代码

 

$arr = array('a','b','d','h','e');

arsort($arr);

 

function testXhp($str){

   return "输入的字符串为".$str;

}

 

$str = 'hello xhprof';

testXhp($str);

 

$data = xhprof_disable();   //返回运行数据

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

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

$xhprof_runs = new XHProfRuns_Default();

$run_id = $xhprof_runs->save_run($data,"xhprof_foo");

echo "<a target='_blank'   href='http://ln.workplace.com/xhprof_html/index.php?run=".$run_id."&source=xhprof_foo'>体验xhprof效果</a>";

?>

 

运行后访问路径:http://ln.workplace.com/xhprof_html/index.php?run=581995c3494bc&source=xhprof_foo

 

点击view full callgraph查看图片展示效果,需要先安装graphviz(图形化工具),libpng

wget http://nchc.dl.sourceforge.net/project/libpng/libpng15/1.5.1/libpng-1.5.1.tar.gz

下载graphiviz,libpng并进行安装后

再次点击view full callgraph

 

posted @ 2016-11-02 16:05  李思琼  阅读(314)  评论(0)    收藏  举报