码迷,mamicode.com
首页 > Web开发 > 详细

Xhprof分析php性能

时间:2019-02-01 20:15:17      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:start   分享   img   class   com   windows   use   公共类   配置   

https://windows.php.net/downloads/pecl/releases/xhprof/0.10.6/ 下载Xhprof版本

技术分享图片

配置一个本地访问url,指向index.php,能访问即可。http://loc.oms.xhprof:9091

 

然后取php官网下载扩展,写在php.ini上

[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" ;目录要事先建好

  在项目里,建立一个公共类文件:

<?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>‘;
        }
    }
}

  在项目文件里,调用类方法:

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=myXhprof

 技术分享图片

Xhprof分析php性能

标签:start   分享   img   class   com   windows   use   公共类   配置   

原文地址:https://www.cnblogs.com/wuxiang12580/p/10346873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!