18

I'm currently working on Symfony project (const VERSION ='2.5.10') and I am using xampp. PHP version is 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

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'

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

9
  • The error msg is very obvious. Your code eats too much RAM and you need to find out which part caused the OOM.
    – Chris Lam
    Commented May 14, 2015 at 5:09
  • @Michael : I already tried that but still it gives me an error about memory limit. What should I do?
    – aiai
    Commented May 14, 2015 at 5:15
  • find wherever it is you're trying to retrieve thousands of rows at once through an ORM, and fix it.
    – pala_
    Commented May 14, 2015 at 5:19
  • We don't know how many memory do you have and what code do you have. This problem is too broad. You need to profile your code with xdebug or blackfire to find place where you exceed all your memory. Commented May 14, 2015 at 5:22

6 Answers 6

19

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:

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

You can also set global parameter in config:

framework:
    profiler:
        collect: false
8
  • where should I really set it ? Is it in config.yml or in config_dev.yml? Sorry,I just really confuse.
    – aiai
    Commented May 14, 2015 at 5:32
  • Your config.dev imports config.yml. And so it all the same. But I would recommend you to place it in your dev-config. Commented May 14, 2015 at 5:42
  • I try that and I got an error : "[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] Unrecognized option "collect" under "framework"
    – aiai
    Commented May 14, 2015 at 6:04
  • 1
    you forgot to place profiler in the middle between framework and collect. I think that with your skills you should choose another framework (or maybe CMS) for your project. Symfony is very complex for you. Commented May 14, 2015 at 6:33
  • 1
    This is not a solution if I need or want to use the Profiler for a page.
    – SteveExdia
    Commented May 10, 2022 at 14:49
6

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 -1 in your php.ini and restart apache.

memory_limit = -1
4
  • I tried that the out of memory error goes away but replace with this one "FatalErrorException: Error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\Editracker\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector.php line 101"
    – aiai
    Commented May 19, 2015 at 8:46
  • Try this as well: max_execution_time = 0
    – BentCoder
    Commented May 19, 2015 at 8:51
  • 1
    If it doesn't solve it then you better try to find the actual bottle-neck in you application. You might have a bigger problem.
    – BentCoder
    Commented May 19, 2015 at 8:55
  • maybe, I really need to. anyways, I tried to open the profiler and I found that the queries is keep on repeating. nut then how can I solve it? I just inherit this project.
    – aiai
    Commented May 19, 2015 at 9:00
2

If the memory limit is only being reached under the Symfony dev environment I would suggest adding the following to 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.

2
  • 4
    is infinite really a sensible amount of memory?
    – ggdx
    Commented May 29, 2019 at 12:37
  • Without knowing much about the system and it's memory needs, this is a better place to set the memory limit then in php.ini. Changing it in app_dev will only affect the running of the dev version of the code, placing this in php.ini means all projects on the host are subject to unlimited memory. When it comes to testing the live version of the project you do not want to forget to change php.ini back. Commented Jul 2, 2019 at 7:27
2

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

Because the Twig uses the PHP var_dump function 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.

Credits to @peezi.

1

This may help :

php -d memory_limit=-1 /usr/local/bin/composer require ggergo/sqlindexhintbundle 
0

Even late to the party, recently I had problems about Out of Memory just 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 var directory 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.

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.