zoukankan      html  css  js  c++  java
  • phalcon: Profiling分析 profilter / Plugin结合,dispatcher调度控制器 监听sql执行日志

    个人觉得profilter 跟 logger 功能差不多,logger的功能在于写入,profilter功能在于sql后及时显示分析。都是对sql执行的的分析:一个是写入log文件,一个是直接在页面展示。

    下面看例子,

    public/index.php:

    $di->set('profiler', function(){
            return new PhalconDbProfiler();
        }, true);
    
    $di['db'] = function() use($di){       
    
            //profile
            $eventManager = new PhalconEventsManager();
            $profiler = new ProfilerEManger();
            $eventManager->attach('db', $profiler);
            $db = new DbAdapter(array(
                "host"     => "localhost",
                "username" => "root",
                "password" => "",
                "dbname"   => "demo",
                "charset"  => "utf8"
            ));
            $db->setEventsManager($eventManager);
            return $db;
    
    };
    

      

    apppluginsProfilerEManger.php

    use PhalconMvcUserPlugin;
    
    
    class ProfilerEManger extends Plugin {
    
    
    
        public function beforeQuery()
        {
           // var_dump($this->db->getSqlStatement());exit;
            $this->profiler->startProfile($this->db->getSqlStatement());
        }
    
        public function afterQuery()
        {
            $this->profiler->stopProfile();
        }
    
    
    
    
    
    }
    

      

    ProfilerController.php
    class ProfilerController extends PhalconMvcController {
    
        public function indexAction()
        {
            $users = array();
            $use = Users::findFirst("id = 1");
            if($use)
            {
                $users = $use->toArray();
            }
            var_dump($users);
    
            $profile = $this->profiler->getLastProfile();
            var_dump($profile);
        }
    
        
    
    }
    

      



  • 相关阅读:
    一个通用的事件监听函数全集
    单应性矩阵
    opencv姿态估计
    opencv相机标定
    Harris角点
    盒滤波Box Filter
    win10+vs2015+pcl1.8.1安装配置
    图像元素遍历
    阈值分割
    二叉树的层次遍历
  • 原文地址:https://www.cnblogs.com/achengmu/p/5996933.html
Copyright © 2011-2022 走看看