且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在生产中禁用 Symfony2 中的探查器?

更新时间:2023-11-19 17:13:58

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 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.