這篇文章主要介紹了關於PHP 7.1安裝xhprof進行效能分析的介紹,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
##安裝擴充功能該xhprof擴充版本是從https://github.com/longxinH/xhprof 取得的(第三方的一個函式庫,官方版本不支援php7)
在web的html目錄下操作:
git clone https://github.com/longxinH/xhprof
編譯擴充功能
cd xhprof/extension/phpize ./configure makemake install
[xhprof] extension=xhprof.so; xhprof.output_dir=/tmp/xhprof
重啟php-fpmsudo service php7.1-fpm restart
<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);// 要检查性能的代码
$xhprof_data = xhprof_disable();
include_once '/var/www/html/xhprof/xhprof_lib/utils/xhprof_lib.php';
include_once '/var/www/html/xhprof/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new \XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, 'your_project');
測試程式碼中要引入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的名字
如果圖表產生錯誤,需要安裝外掛程式:
<?php function test1(){ for($i=0;$i<10;$i++){ echo 'aaa'.$i.'<br>'; } }// 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 7.1安裝xhprof進行效能分析的介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!