简体   繁体   English

如何禁用 Symfony 2 分析器栏?

[英]How do I disable the Symfony 2 profiler bar?

It's not adding anything and it makes the page slower and I want it gone.它没有添加任何东西,它使页面变慢,我希望它消失。 Don't ask.不要问。 There's little about the profiler on the website and nothing in the app config.网站上几乎没有关于分析器的信息,应用程序配置中也没有。

This setting is in app/config/config_dev.yml : 此设置位于app/config/config_dev.yml

web_profiler:
    toolbar: true
    intercept_redirects: false

Additional: if you want to disable it for a special action in your controller than use this: 附加:如果要在控制器中为特殊操作禁用它而不是使用它:

if ($this->container->has('profiler'))
{
    $this->container->get('profiler')->disable();
}

If you set framework.profiler.collect to false in your config.yml, the profiler bar won't be shown (even if web_profiler.toolbar is set to true). 如果在config.yml中将framework.profiler.collect设置为false ,则不会显示探查器栏(即使web_profiler.toolbar设置为true)。

 framework:
    profiler:
        collect: false

This then allows you to selectively activate collectors in your code manually, like this: 然后,您可以手动选择性地激活代码中的收集器,如下所示:

$this->container->get('profiler')->enable();

Documentation here: http://symfony.com/doc/current/reference/configuration/framework.html#collect 文档: http//symfony.com/doc/current/reference/configuration/framework.html#collect

Symfony 5.3.7 Symfony 5.3.7

I changed the toolbar value to false in the web_profiler.yaml and the toolbar was disabled.我在 web_profiler.yaml 中将工具栏值更改为 false,工具栏被禁用。

{# [root_directory]/config/packages/dev/web_profiler.yaml #}

web_profiler:
    toolbar: true  --> Change to false
    intercept_redirects: false

Try this 试试这个

framework:
    profiler: { only_exceptions: true }

in your app/config/config_dev.yml 在你的app/config/config_dev.yml

If you have created a new Symfony project since Symfony 2.5, these parameters are set in app/config/paramaters.yml 如果您从Symfony 2.5开始创建了一个新的Symfony项目,则这些参数在app/config/paramaters.yml

parameters:
    # ...
    debug_toolbar: true
    debug_redirects: false

Just set debug_toolbar to false . 只需将debug_toolbar设置为false

To still get output in /_profiler but without the toolbar, you can cheat: 要仍然在/ _profiler中输出但没有工具栏,你可以作弊:

$request->headers->add(array('X-Requested-With' => 'XMLHttpRequest'));

That's because in WebProfilerBundle/EventListener/WebDebugToolbarListener.php there's an explicit check for this before injecting the toolbar. 那是因为在WebProfilerBundle / EventListener / WebDebugToolbarListener.php中,在注入工具栏之前会对此进行显式检查。

If you are worried about performance - then you should not be running under dev. 如果你担心性能 - 那么你不应该在dev下运行。 Dev also limits caching and can pull in additional bundles. Dev也限制了缓存,可以引入额外的包。

Run in prod mode and warm your cache before you run performance tests. 在运行性能测试之前,以prod模式运行并加热缓存。

Another way that seems to disable it, is to not have _dev in the routing of the application. 另一种似乎禁用它的方法是在应用程序的路由中没有_dev

So for me in a bitnami install of Symfony 2, simply by changing app/conf/httpd-app.conf slightly it would change the program: 所以对于我在Symfony 2的bitnami安装中,只需稍微更改app/conf/httpd-app.conf就会改变程序:

RewriteBase /symfony/app_dev.php

to

RewriteBase /symfony/

and it would keep the toolbar from coming up. 它会阻止工具栏出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM