在生产中使用Symfonys转储

时间:2017-03-19 13:42:17

标签: php symfony

我在我们的一个应用程序中使用了dump函数,我们的客户在开发过程中习惯了它(tbh我不知道它在prod中工作)。现在应用程序正在运行,这意味着不再需要debug模式 - 并且不再有dump功能。

有没有办法在prod期间启用dump功能?

3 个答案:

答案 0 :(得分:1)

尽管在生产环境中使用dump()有奇怪的意愿......

如果我没有弄错,dump()来自DebugBundledev仅在testpublic function registerBundles() { $bundles = [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new AppBundle\AppBundle(), ]; if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); if ('dev' === $this->getEnvironment()) { $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle(); } } return $bundles; } env中启用。

DebugBundle

正如您所看到的,if仅在之前提及的环境中注册。将其移出dump()可能会允许您在生产中使用res.writeHead(200, { 'Content-Type': 'text/html' }); res.write('<h2>Connected Users are:</h2>' + chunk); res.end();

答案 1 :(得分:0)

您确实必须将此行添加到 AppKernel.php:

 $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();

但也要将 app.php 中的这个布尔值从 false 更改为 true:

$kernel = new AppKernel('prod', true); // true is replacing false, in second argument here

已针对 Symfony 4.4 进行测试并有效。

答案 2 :(得分:0)

阅读Symfony文档?,函数'dump()'是'VarDumper'组件的一部分,它是一个开发依赖,所以如果你想在prod中使用它,你需要将它安装为所需的依赖:

❌ $ composer require --dev symfony/var-dumper

✔ $ composer 需要 symfony/var-dumper

  • ? 但我想在生产中使用它不是一个好习惯,它可能会显示敏感信息。
相关问题