如何在生产中禁用 Symfony2 中的探查器? [英] How to disable profiler in Symfony2 in production?

查看:28
本文介绍了如何在生产中禁用 Symfony2 中的探查器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在生产环境中禁用 Symfony2 中的分析器?

How to disable profiler in Symfony2 in production?

我不是说工具栏 - 我是说分析器.

I do not mean the toolbar - I mean the profiler.

我想在生产中禁用它,我将它广泛用于开发,因此删除其捆绑包的解决方案是行不通的.

I want to disable it in production, I use it extensively for development so the solution with removing its bundle is a no-go.

我尝试将 framework.profiler.only_exceptions 设置为 true.我已经尝试完全删除 framework.profiler 部分.无论 每个 请求和 每个 响应包含 x-debug-token 标头后,profiler.db 会增长什么.

I have tried setting framework.profiler.only_exceptions to true. I have tried removing the framework.profiler section altogether. No matter what the profiler.db is growing after every request and every response contains x-debug-token header.

我已经仔细检查了配置文件(config.yml 和 config_prod.yml),一切似乎都没有问题.

I have double-checked the config files (config.yml and config_prod.yml) and everything seems to be fined.

更重要的是 app/console router:dump-apache --no-debug 命令总是转储 _wdt_profiler 路由,但是我的routing_prod.yml 中没有它们,而且在尝试从浏览器 (404) 访问它们时,它们似乎也不存在.

What's more the command app/console router:dump-apache --no-debug always dumps the _wdt and _profiler routes, but I don't have them in my routing_prod.yml and they don't seem to be present when trying to access them from the browser (404).

我正在运行 symfony 2.0,我现在不会升级,因为 2.1 中的一些重大更改需要重写许多元素.在初始部署之前启动它是不明智的.

I'm running symfony 2.0 and I won't upgrade right now because of some major changes in 2.1 which would require a rewrite of many elements. It wouldn't be wise to start it just before initial deployment.

推荐答案

Symfony >= 2.2

从 Symfony 2.2 开始,分析器支持框架配置中的 enabled 标志,并在 test 环境中默认禁用.

Symfony >= 2.2

As of Symfony 2.2 the profiler supports an enabled flag in the framework's configuration and is disabled by default in the test environment.

# app/config/config_test.yml
framework:
    profiler:
        enabled: false

请参阅此关于分析的博客条目 由 Fabien Potencier 和 FrameworkBundle 配置参考 了解更多详情.

See this Blog entry about Profiling by Fabien Potencier and the FrameworkBundle configuration reference for more details.

更新:此标志在 Symfony 4.0.

Update: This flag is still valid in Symfony 4.0.

在 Symfony <= 2.1 中,如果配置中没有 framework.profiler 键,则分析器将完全禁用.

In Symfony <= 2.1 The profiler is disabled entirely if there's no framework.profilerkey in the configuration.

您可以在 ProfilerPass Symfony2 FrameworkBundle 配置.

You can see this in the ProfilerPass of the Symfony2 FrameworkBundle configuration.

这是默认 config.ymlconfig_prod.yml(包括前者)的情况.因此,如果您没有修改默认配置,那就没问题了.

This is the case for the default config.yml and config_prod.yml (which includes the former). So if you didn't tinker with the default configurations you're fine.

config_dev.yml 中,但是默认设置是:

In config_dev.yml however the default setting is:

framework:
    profiler: { only_exceptions: false }

启用对 dev 环境和所有导入 config_dev.yml 的环境(如 config_test.yml)进行分析.

Which enables profiling for the dev environment and all enviroments that import config_dev.yml like config_test.yml.

如果您想在后续配置中取消设置分析器值,请使用:

framework:
    profiler: false

{}~ 之类的值不会取消设置值.你必须使用 false.

Values like {} or ~ won't unset the value. You have to use false.

这篇关于如何在生产中禁用 Symfony2 中的探查器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆