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

下面看例子,

public/index.php:

$di->set('profiler', function(){
return new \Phalcon\Db\Profiler();
}, true); $di['db'] = function() use($di){ //profile
$eventManager = new \Phalcon\Events\Manager();
$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; };

  

app\plugins\ProfilerEManger.php

use \Phalcon\Mvc\User\Plugin;

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 \Phalcon\Mvc\Controller {

    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);
} }

  

												

phalcon: Profiling分析 profilter / Plugin结合,dispatcher调度控制器 监听sql执行日志的更多相关文章

  1. phalcon: plugin 结合Manager事件管理、dispatcher调度控制器 监听sql日志记录或其他拦截出来

    可能用到的类 phalcon\mvc\use\plugin Phalcon\Mvc\Dispatcher as MvcDispatcher Phalcon\Events\Manager as Even ...

  2. phalcon: eventManager事件管理(结合dispatcher调度控制器)制作简单的acl

    制作简单的acl, dispatcher(专门用来加载或调度或跳转到相应的url地址即XXXcontroller的调度器或控制器,能够在controller执行前对controller进行停止跳转等) ...

  3. phalcon: dispatcher调度控制器

    phalcon: dispatcher调度控制器 我所理解的dispatcher调度控制器,实际上是对 router或者特定的url参数给与重组. 引用特定的类: //add use Phalcon\ ...

  4. phalcon——调度控制器

    将侦听者绑定到组件上: use Phalcon\Mvc\Dispatcher as MvcDispatcher, Phalcon\Events\Manager as EventsManager; $d ...

  5. Hadoop 三大调度器源码分析及编写自己的调度器

    如要转载,请注上作者和出处.  由于能力有限,如有错误,请大家指正. 须知: 我们下载的是hadoop-2.7.3-src 源码. 这个版本默认调度器是Capacity调度器. 在2.0.2-alph ...

  6. Struts2 源码分析——调结者(Dispatcher)之执行action

    章节简言 上一章笔者写关于Dispatcher类如何处理接受来的request请求.当然读者们也知道他并非正真的执行action操作.他只是在执行action操作之前的准备工作.那么谁才是正真的执行a ...

  7. Struts2 源码分析——调结者(Dispatcher)之准备工作

    章节简言 上一章笔者讲到关于struts2过滤器(Filter)的知识.让我们了解到StrutsPrepareFilter和StrutsExecuteFilter的作用.特别是StrutsPrepar ...

  8. 子查询优化--explain与profiling分析语句

    今天想的利用explain与progiling分析下语句然后进行优化.本文重点是如何通过explain与profiling分析SQL执行过程与性能.进而明白索引的重要性. 表的关系如下所示: 原始的查 ...

  9. 鸿蒙内核源码分析(时钟任务篇) | 触发调度谁的贡献最大 | 百篇博客分析OpenHarmony源码 | v3.05

    百篇博客系列篇.本篇为: v03.xx 鸿蒙内核源码分析(时钟任务篇) | 触发调度谁的贡献最大 | 51.c.h .o 任务管理相关篇为: v03.xx 鸿蒙内核源码分析(时钟任务篇) | 触发调度 ...

随机推荐

  1. nylg 640 Geometric Sum

    Geometric Sum 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 Compute (a + a^2 + … + a^n) mod m.(a+a2+…an)m ...

  2. Codeforces Round #372 (Div. 2) A

    Description ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecut ...

  3. Java总结反射

    [案例1]通过一个对象获得完整的包名和类名 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package Reflect;   /**  * 通过一个对象获得完整的包名和类名 ...

  4. for循环以及复杂if else 例题

    for循环语句 例一. 请输入一个整数,求1加到这个整数的和 例二 请从1到100 以内和7 有关的数字 例三,请设计一个游戏,前20关每关的分数是本身,21到30 是10分每关.31到40是20分每 ...

  5. Json 入门例子(form表单)【0】

    <script> $(function () { var aa = $("#fm").serialize().replace(/\+/g, ""); ...

  6. fastboot 教程

    参考: http://blog.csdn.net/geniusmen/article/details/7892398 http://www.cnblogs.com/eastnapoleon/p/327 ...

  7. UICollectionView 使用

    /** 初始化UICollectionView */ UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc ...

  8. CodeForces 373B Making Sequences is Fun

    Making Sequences is Fun Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Music Player团队项目(一)

    团队成员及分工 团队: Blue 团队共有六人 姓名:     学号后四位:       贡献分: 张   宇(队长)  1152          1+1.8=2.8分 侯贺琦          1 ...

  10. FZU 2221 RunningMan(跑男)

    Problem Description 题目描述 ZB loves watching RunningMan! There's a game in RunningMan called 100 vs 10 ...