PHP性能監控軟件XHProf的安裝和使用(原創)

PHP性能監控軟件XHProf的安裝和使用(原創)
作者:餘超 EMAIL:[email protected]

XHProf是facebook開源出來的一個php輕量級的性能分析工具,跟Xdebug類似。相對於XDebug來說配置更簡單、更輕量級、更可控。
環境:linux+php+apache
一、安裝XHProf
//下載到任意目錄
[yuchao@yuchao-Latitude-E5410 dev]$wget http://pecl.php.net/get/xhprof-0.9.2.tgz  
//解壓文件
[yuchao@yuchao-Latitude-E5410 dev]$tar zxf xhprof-0.9.2.tgz  
//進入解壓後的文件夾
[yuchao@yuchao-Latitude-E5410 dev]$cd xhprof-0.9.2  
//拷貝xhprof_html xhprof_lib這兩個文件夾到您的webroot目錄,筆者的是/opt/lampp/htdocs
[yuchao@yuchao-Latitude-E5410 dev]$cp -r xhprof_html xhprof_lib /opt/lampp/htdocs/xhprof
//進入extension文件夾
[yuchao@yuchao-Latitude-E5410 dev]$cd extension
//執行phpize(筆者的phpize在/user/local/php/bin/phpize)
/user/local/php/bin/phpize
[yuchao@yuchao-Latitude-E5410 extension]$pwd
/home/yuchao/dev/xhprof-0.9.2/extension
[yuchao@yuchao-Latitude-E5410 extension]$phpize
[yuchao@yuchao-Latitude-E5410 extension]$ls
acinclude.m4    config.guess  config.m4      configure     libtool             Makefile.global   modules        xhprof.c
aclocal.m4      config.h      config.nice    configure.in  ltmain.sh           Makefile.objects  php_xhprof.h   xhprof.la
autom4te.cache  config.h.in   config.status  include       Makefile            missing           run-tests.php  xhprof.lo
build           config.log    config.sub     install-sh    Makefile.fragments  mkinstalldirs     tests
[yuchao@yuchao-Latitude-E5410 extension]$
[yuchao@yuchao-Latitude-E5410 dev]$./configure
[yuchao@yuchao-Latitude-E5410 dev]$make
[yuchao@yuchao-Latitude-E5410 dev]$make test
[yuchao@yuchao-Latitude-E5410 dev]$sudo make install
XHProf安裝完畢你將會看見編譯生成的/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xhprof.so模塊
接下來我們需要配置php.ini,使php能加載XHProf編譯後的xhprof.so模塊,在php.ini中加入以下
[xhprof]
extension=xhprof.so
xhprof.output_dir=/opt/lampp/var/xhprof/


說明:xhprof.output_dir指的是xhprof分析結果存放的目錄

現在我們開始測試:

examples目錄下面有一個sample.php,


然後運行http://localhost/xhprof/examples/sample.php,將會在/opt/lampp/var/xhprof/下生成分析日誌

4e6049216b797.xhprof_foo文件名中“4e6049216b797”爲標識也就是傳說中的id是變化的,“xhprof_foo”是文件後綴。
查看這條分析後的數據

比如剛剛生成的數據日誌,我們通過url地址訪問地址是http://localhost/xhprof_html/index.php?run=4e6049216b797&source=xhprof_foo 


這樣你就會看見統計後的數據了,


當然也有圖形化的界面,請自己Google之。


發佈了46 篇原創文章 · 獲贊 5 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章