https://windows.php.net/downloads/pecl/releases/xhprof/0.10.6/ 下載Xhprof版本php
配置一個本地訪問url,指向index.php,能訪問便可。http://loc.oms.xhprof:9091前端
而後取php官網下載擴展,寫在php.ini上java
[xhprof] extension=php_xhprof.dll ; directory used by default implementation of the iXHProfRuns ; interface (namely, the XHProfRuns_Default class) for storing ; XHProf runs. xhprof.output_dir="D:/xampp/php/xhprof" ;目錄要事先建好
在項目裏,創建一個公共類文件:windows
<?php namespace Order\Common\Tool; class XhprofHelper { public static function start() { if(extension_loaded('xhprof')){ //載入下載的XHPROF包中的2個文件夾 include_once __DIR__ . '/xhprof-0.9.4/xhprof_lib/utils/xhprof_lib.php'; include_once __DIR__ . '/xhprof-0.9.4/xhprof_lib/utils/xhprof_runs.php'; //xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); xhprof_enable( XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY); } } public static function stop() { if(extension_loaded('xhprof')){ $ns = 'myXhprof'; //關閉profiler $xhprofData = xhprof_disable(); //實例化類 $xhprofRuns = new \XHProfRuns_Default(); $runId = $xhprofRuns->save_run($xhprofData, $ns); //前端展現庫的URL $url = 'http://loc.oms.xhprof:9091/index.php'; $url .= '?run=%s&source=%s'; //變量替換 $url = sprintf($url, $runId, $ns); //輸入URL echo '<a href="'.$url.'" target="_blank">查看結果</a>'; } } }
在項目文件裏,調用類方法:url
public function getSearchConfig(){ XhprofHelper::start(); $lan = I('get.language', 'zh', 'trim');
$selfPickupType = C('TaiwanYourPickup'); $data['selfPickupType'] = $selfPickupType[$lan]; XhprofHelper::stop();exit;
訪問:http://loc.oms.xhprof:9091/callgraph.php?run=5c5430d519c87&source=myXhprofspa