#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 歡迎你們的加入!