php symfony 内存不足错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30229637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:38:35  来源:igfitidea点击:

Out of memory error in symfony

phpsymfonyout-of-memory

提问by aiai

I'm currently working on Symfony project (const VERSION ='2.5.10') and I am using xampp. PHP version is 5.5.19.

我目前正在研究 Symfony 项目(const VERSION ='2.5.10')并且我正在使用 xampp。PHP 版本为 5.5.19。

My problem is everytime I run my dev environment I get an error :

我的问题是每次运行我的开发环境时都会出现错误:

OutOfMemoryException: Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 3358976 bytes) in C:\xampp\htdocs\Editracker\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Profiler\FileProfilerStorage.php line 153

OutOfMemoryException:错误:在 C:\xampp\htdocs\Editracker\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Profiler\FileProfiler153php 中,允许的内存大小为 1073741824 字节已用尽(试图分配 3358976 字节)

and everytime I refresh the page it gives different memory size. I also think that this is also the reason why my dev environment takes a lont time before it refreshes the page.

每次刷新页面时,它都会给出不同的内存大小。我也认为这也是我的开发环境在刷新页面之前需要很长时间的原因。

Your help is appreciated.

感谢您的帮助。

php.ini

配置文件

memory_limit= '256M'

内存限制 = '256M'

I tried to increase my memory limit,still it gives an error about memory limit

我试图增加我的内存限制,但它仍然给出关于内存限制的错误

回答by Michael Sivolobov

The most eager component in Symfony is a profiler. If you don't need profiler in some particular actions you can disable it via code:

Symfony 中最热切的组件是分析器。如果您在某些特定操作中不需要分析器,您可以通过代码禁用它:

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

You can also set global parameter in config:

您还可以在配置中设置全局参数:

framework:
    profiler:
        collect: false

回答by BentCoder

You either disable symfony profiler (I don't think this is what you want as far as I know) or set limit to unlimited with -1in your php.ini and restart apache.

您要么禁用 symfony 分析器(据我所知,我认为这不是您想要的)或-1在您的 php.ini中将限制设置为无限制并重新启动 apache。

memory_limit = -1

回答by valdeci

I solved the Out of memory error on the Twig debug installing the XDebug.

我在安装 XDebug 的 Twig 调试中解决了内存不足错误。

Because the Twig uses the PHP var_dumpfunction internally, install the XDebug is a good idea, because it limits the var_dump()output of arrays and objects to 3 levels deep, as we can see on the documentation.

因为 Twig 在var_dump内部使用 PHP函数,所以安装 XDebug 是一个好主意,因为它将var_dump()数组和对象的输出限制为 3 级深度,正如我们在文档中看到的那样。

Credits to @peezi.

学分@peezi

回答by Fabiano

Even late to the party, recently I had problems about Out of Memoryjust accessing app.php file with Symfony 3.4. Turns out that when you have SELinux set to enforcing, even if you set the permissions of vardirectory inside your project to 777, it won't be able to write on it. If you follow the steps in the official documentation about how deploy in production, it will return a response code 500 and write in web server's error log only that PHP has exhausted the memory limit.

即使参加晚会,最近我在Out of Memory使用 Symfony 3.4 访问 app.php 文件时也遇到了问题。原来,当你把 SELinux 设置为 时enforcing,即使你将var项目中目录的权限设置为 777,它也无法写入。如果您按照官方文档中关于如何在生产中部署的步骤进行操作,它将返回响应代码 500 并仅在 Web 服务器的错误日志中写入 PHP 已用完内存限制。

I'm no expert in SELinux, but the only way I could solve this problem was disabling SELinux, but edition /etc/selinux/configfile setting SELINUX=disabledand restarting the OS.

我不是 SELinux 方面的专家,但我解决这个问题的唯一方法是禁用 SELinux,而是/etc/selinux/config设置版本文件SELINUX=disabled并重新启动操作系统。

Again, there's reason to SELinux exists and proper configuration isn't found easily using Symfony's varsub-folders and can get hard to solve this problem without thinking of disabling SELinux.

同样,SELinux 存在是有原因的,使用 Symfony 的var子文件夹不容易找到正确的配置,如果不考虑禁用 SELinux,就很难解决这个问题。

回答by lookbadgers

If the memory limit is only being reached under the Symfony dev environment I would suggest adding the following to web/app_dev.php

如果仅在 Symfony 开发环境下达到内存限制,我建议将以下内容添加到 web/app_dev.php

ini_set('memory_limit', '-1');

This way you can continue to test the production with a sensible amount of memory. Modifying the whole environment via php.ini could hide an error down the line.

通过这种方式,您可以使用合理的内存量继续测试产品。通过 php.ini 修改整个环境可能会隐藏错误。