PhalApi-Xhprof -- Facebook开源的轻量级PHP性能分析工具

#PhalApi-Xhprof -- Facebook开源的轻量级PHP性能分析工具php

##前言html

Facebook开源的轻量级PHP性能分析工具,很是爽但愿你们喜欢git

附上:api

官网地址:http://www.phalapi.net/工具

开源中国Git地址:http://git.oschina.net/dogstar/PhalApi/tree/release性能

开源中国拓展Git地址:http://git.oschina.net/dogstar/PhalApi-Library优化

##1. 安装.net

首先须要安装配置Xhprofdebug

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

tar zxf xhprof-0.9.2.tgz

cd xhprof-0.9.2/extension/

sudo phpize
./configure --with-php-config=/usr/local/php/bin/php-config
sudo make
sudo 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=<directory_for_storing_xhprof_runs> xhprof.output_dir=/tmp/xhprofcode

经过phpinfo()看到xhprof扩展则为安装成功

注意:xhprof.output_dir=/tmp/xhprof,设置必须统一否则须要自行替换编译出来html的问题到拓展项目中

而后对咱们的index.php文件作如此的改造

在头部加上:

if (!empty($_GET['__debug__'])) {
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}

在尾部加上: if (!empty($_GET['debug'])) {

$data = xhprof_disable();

    include API_ROOT . "/Library/Xhprof/utils/xhprof_lib.php";
    include API_ROOT . "/Library/Xhprof/utils/xhprof_runs.php";
    $objXhprofRun = new XHProfRuns_Default();//数据会保存在php.ini中xhprof.output_dir设置的目录去中
    echo $objXhprofRun->save_run($data, "developers");
}

这个时候咱们访问的时候带入请求参数__debug__能够得到以下返回

而后咱们访问http://xxxx/Library/Xhprof/index.php能够的到以下界面

咱们能够看到有一个key和上面生成的同样的咱们点击进去:

##2. 总结

但愿此拓展可以给你们带来方便以及实用,此扩展能够分析出在整个运行途中的消耗用时能够针对进行优化,在压力状况下能够很是好的辨别出慢代码出如今哪里!

注:笔者能力有限有说的不对的地方但愿你们可以指出,也但愿多多交流!

官网QQ交流群:421032344 欢迎你们的加入!

相关文章
相关标签/搜索