symfony - Symfony 事件 - 如何不通过 Profiler 或预热触发内核事件
问题描述
Symfony v3.4 项目,具有多个已定义的侦听器/订阅者,用于各种目的。他们kernel.request
与kernel.controller
事件有关。
我注意到所有这些也会被 Symfony 的分析器工具发出的任何请求触发,以及在 Symfony 正在预热代码缓存的情况下。
真的应该这样吗?当页面请求来自 Profiler 时,是否有一种很好的方法可以不触发定义的 kernel.* 事件(至少是特定事件)?最好的方法是什么?
关于在热身时排除这些事件 - 我相信如果它不会做所有的连接等,热身会更快,所以它的发展会稍微快一些。
我在这里看到了一个较早的自我回答问题:如何防止 Symfony 分析器访问或执行侦听器,但在我的用例中,这似乎需要做太多工作 - 更改系统中的所有现有控制器。此外,其他提供的评论/补丁似乎并不是处理这个问题的好方法。感谢您的任何见解。
解决方案
不幸的是,这是不可能的,因为它WebProfilerBundle
依赖于symfony 的事件系统
由于探查器路由以_
前缀开头,您可以通过以下方式忽略它:
$route = $event->getRequest()->attributes->get('_route');
if (strpos($route, '_') === 0) {
return;
}
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
推荐阅读
- mongodb - 为什么按项目数量对总和数量进行分组不为零,但它显示了许多带有字母 e“1.1102230246251565e-16”的数字与聚合 mongodb?
- angular - Angular 7嵌套延迟加载问题
- powerbi - Dax 查询 - 运行总计%
- python - 字典:对象作为值不起作用
- android - 将导航组件与多个活动一起使用
- php - 上传图像时出错 PHP Fileinfo 扩展必须安装/启用才能使用干预图像
- java - 请求被拒绝,因为没有找到多部分边界 angular+spring
- shopware - 致命错误:未捕获的 PDOException:SQLSTATE [42S22]:找不到列:1054 中的“字段列表”中的未知列“swag_advanced_cart_cookie_name_hash”
- node.js - 我一直在尝试将我的节点连接到 MongoDB,但我遇到了错误
- javascript - Moodle 页面包含的 js 文件仍然显示 ReferenceError: wordfindgame is not defined