首頁  >  文章  >  後端開發  >  PHP 7.1安裝xhprof進行效能分析的介紹

PHP 7.1安裝xhprof進行效能分析的介紹

不言
不言原創
2018-07-04 17:18:281671瀏覽

這篇文章主要介紹了關於PHP 7.1安裝xhprof進行效能分析的介紹,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

##安裝擴充功能該xhprof擴充版本是從https://github.com/longxinH/xhprof 取得的(第三方的一個函式庫,官方版本不支援php7)

下載並編譯xhprof擴充

在web的html目錄下操作:
git clone https://github.com/longxinH/xhprof

編譯擴充功能

cd xhprof/extension/phpize
./configure 
makemake install

修改php.ini配置

[xhprof]
extension=xhprof.so;
xhprof.output_dir=/tmp/xhprof

其中xhprof.output_dir 是xhprof 的輸出目錄,每次執行xhprof 的save_run 方法時都會產生一個run_id.project_name.xhprof 檔案。這個目錄在哪裡並不重要。注意此路徑的權限要可讀寫! !否則檔案無法產生成功

重啟php-fpmsudo service php7.1-fpm restart

##新增測試程式碼





<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);// 要检查性能的代码
$xhprof_data = xhprof_disable();
include_once &#39;/var/www/html/xhprof/xhprof_lib/utils/xhprof_lib.php&#39;;
include_once &#39;/var/www/html/xhprof/xhprof_lib/utils/xhprof_runs.php&#39;;
$xhprof_runs = new \XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, &#39;your_project&#39;);

測試程式碼中要引入xhprof_lib.php和xhprof_runs.php兩個檔案

查看生成報表

需要存取:xhprof/xhprof_html/index.php檔案檢視:

http://localhost/xhprof/xhprof_html/index.php?run=5b35d3dfa8c29&source=your_projectrun後的參數為$run_id,source參數為your_project的名字
如果圖表產生錯誤,需要安裝外掛程式:

sudo apt-get install graphviz

實際示範程式碼

######
<?php
function test1(){
for($i=0;$i<10;$i++){
echo &#39;aaa&#39;.$i.&#39;<br>&#39;;
}
}// start profilingxhprof_enable();

test1();
// stop profiler
$xhprof_data = xhprof_disable();
// display raw xhprof data for the profiler runprint_r($xhprof_data);
include_once "xhprof_lib.php";include_once "xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_test"
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test");echo "---------------\n".
"Assuming you have set up the http based UI for \n".
"XHProf at some address, you can view run at \n".
"http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_test\n".
"---------------\n";
###以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網! ######相關推薦:#########LAMP、LNMP和LNAMP的區別和安裝###############使用Wamp來建立Php本地開發環境以及HBuilder調試的方法#########

以上是PHP 7.1安裝xhprof進行效能分析的介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn