php xhprof使用實例詳解
xhprof php性能分析
1.clone xhprof 此版本為github第三方擴展 (php官房不支持 php 7)
https://github.com/longxinH/xhprof
2.extension 目錄為擴展源碼安狀擴展即可
phpize && ./configure && make && make install
3.編輯php.ini 啟用xhprof擴展
[xhprof] extension = xhprof.so xhprof.output_dir = /tmp/xhprof ;性能分析數(shù)據(jù)文件存放位置 需要php用戶有可寫可讀權限
4.對項目入口文件添加代碼
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS +
XHPROF_FLAGS_CPU +
XHPROF_FLAGS_MEMORY);
register_shutdown_function(function (){
$data = xhprof_disable();
//xhprof_lib 在第一步git clone 后的文件夾里面
include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_lib.php';
include '/mnt/d/www/xhprof/xhprof_lib/utils/xhprof_runs.php';
$objXhprofRun = new XHProfRuns_Default();
$objXhprofRun->save_run($data, "table"); //生成數(shù)據(jù)文件后綴
});
5.nginx 或者 apache 創(chuàng)建 網占目錄(apache為例)
<VirtualHost *:80>
ServerName xhprof.com
## xhprof/xhprof_html 在第一步git clone 后的文件夾里面
DocumentRoot "/mnt/d/www/xhprof/xhprof_html"
DirectoryIndex index.html index.php index.html
<Directory "/mnt/d/www/xhprof/xhprof_html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
6.訪問 http://xhprof.com/ (上面虛擬主機配置的 本地域名需要host )顯示每次程序運行生成的性能分析數(shù)據(jù)文件 點擊可以打 開


7.如果想要查看性能圖點擊 view full callgraph (服務器需要安裝 graphviz 庫)
ubuntu 安裝方法 (pro apt-get install graphviz)
8.顯示效果圖

總結
以上所述是小編給大家介紹的php xhprof使用實例詳解 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
相關文章
ThinkPHP實現(xiàn)轉換數(shù)據(jù)庫查詢結果數(shù)據(jù)到對應類型的方法
這篇文章主要介紹了ThinkPHP實現(xiàn)轉換數(shù)據(jù)庫查詢結果數(shù)據(jù)到對應類型的方法,涉及thinkPHP模型類操作及針對源碼文件的相關修改方法,需要的朋友可以參考下2017-11-11
Laravel 5.4中migrate報錯: Specified key was too long error的解決
今天在執(zhí)行l(wèi)aravel migrate時出現(xiàn)異常,找了好半天才找到問題所在,所以這篇文章主要給大家介紹了關于Laravel 5.4中migrate報錯: Specified key was too long error的解決方法,需要的朋友可以參考下。2017-11-11
基于PHP+Mysql簡單實現(xiàn)了圖書購物車系統(tǒng)的實例詳解
這篇文章主要介紹了基于PHP+Mysql簡單實現(xiàn)了圖書購物車系統(tǒng)的實例詳解,文章通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下 面隨著小編來一起學習學習吧2020-08-08
CodeIgniter框架數(shù)據(jù)庫基本操作示例
這篇文章主要介紹了CodeIgniter框架數(shù)據(jù)庫基本操作,結合實例形式分析了CodeIgniter框架針對mysql數(shù)據(jù)庫的配置、用戶注冊、信息查詢、修改及刪除等基本操作技巧,需要的朋友可以參考下2018-05-05

