Xhprof php效能測試工具用法小結
Xhprof 是facebook推出的輕量級的php效能分析工具,和Xdebug相比,XHProf更加易用和可控,尤其是產生流程圖和調試資料對比的功能很好很強大。 下面簡單介紹下Xhprof的安裝及使用。
1、安裝
可以從頁面 下載相應版本及瞭解各個版本依賴條件。 安裝前,先假設php的bin目錄是:/usr/local/php/bin
[root@localhost extension]# ln -s /usr/local/php/bin/phpize /usr/bin/phpize[root@localhost tool]# wget http://pecl.php.net/get/xhprof-0.9.2.tgz[root@localhost tool]# tar -zxvf xhprof-0.9.2.tgz [root@localhost tool]# cd xhprof-0.9.2/extension/[root@localhost tool]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@localhost tool]# make[root@localhost tool]# make install
通過上面的操作,如果運氣不是非常糟糕的話,你應該看到類似這樣的提示:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
進入到php擴充庫目錄/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ ,你將看到xhprof.so 共用庫檔案。
2、配置
在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=xhprof.output_dir=/tmp/xhprof
重啟下php,就可以在使用xhprof了。
3、拷貝檔案
把xhprof-0.9.2目錄下的目錄xhprof_html 和 xhprof_lib 下的所有檔案拷貝到你網站的主目錄下,假設網站主目錄:/opt/wordpress
[root@localhost xhprof-0.9.2]# cp -R xhprof_* /opt/wordpress
4、使用
參考下面的解釋說明:
save_run($data, "xhprof"); //查看運行結果的url//run的值來源於save_run的傳回值//source值來源於save_run的第二個參數 //www.abc.com 需要用自己的網域名稱替換echo "http://www.abc.com/xhprof_html/index.php?run=".$run_id."&source=xhprof";
在瀏覽器中開啟輸出的url,及可看到相關的效能資訊。