17

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

aiai
  • 1,129
  • 2
  • 11
  • 21
  • 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 May 14 '15 at 05:09
  • possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – Michael Sivolobov May 14 '15 at 05:11
  • @Michael : I already tried that but still it gives me an error about memory limit. What should I do? – aiai May 14 '15 at 05:15
  • find wherever it is you're trying to retrieve thousands of rows at once through an ORM, and fix it. – pala_ May 14 '15 at 05: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. – Michael Sivolobov May 14 '15 at 05:22
  • ahm.... how can I do it? I'm not familiar with xdebug or blackfire.Can you teach me how to do it ? I'm new in symfony you know. – aiai May 14 '15 at 05:25
  • It is not about Symfony. It is about PHP. The most useful link for it: http://ow.ly/MVHox – Michael Sivolobov May 14 '15 at 05:37
  • I got this error every time the cookie is biggest than 4k – manix May 19 '15 at 08:45
  • how did you solve it? – aiai May 19 '15 at 08:47

6 Answers6

20

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
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
  • where should I really set it ? Is it in config.yml or in config_dev.yml? Sorry,I just really confuse. – aiai May 14 '15 at 05: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. – Michael Sivolobov May 14 '15 at 05:42
  • I try that and I got an error : "[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] Unrecognized option "collect" under "framework" – aiai May 14 '15 at 06: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. – Michael Sivolobov May 14 '15 at 06:33
  • I follow your example, so what could be the problem? and about changing the framework I am using, I just can't because I just inherent this project and need to enhance it functionality.I am just starting to learn this framework. – aiai May 14 '15 at 07:02
  • In my example `collect` is under `profiler` section (8 spaces). And `profiler` in `framework` section (4 spaces), `framework` is in global space (no spaces at all). In your error said that `collect` is under `framework` section that doesn't comply with my example. – Michael Sivolobov May 14 '15 at 07:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77777/discussion-between-xammeil-and-michael-sivolobov). – aiai May 14 '15 at 07:16
  • This is not a solution if I need or want to use the Profiler for a page. – SteveExdia May 10 '22 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
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • 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 May 19 '15 at 08:46
  • Try this as well: `max_execution_time = 0` – BentCoder May 19 '15 at 08: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 May 19 '15 at 08: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 May 19 '15 at 09: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.

lookbadgers
  • 988
  • 9
  • 31
  • 3
    is infinite really a `sensible amount of memory`? – ggdx May 29 '19 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. – lookbadgers Jul 02 '19 at 07: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.

valdeci
  • 13,962
  • 6
  • 55
  • 80
1

This may help :

php -d memory_limit=-1 /usr/local/bin/composer require ggergo/sqlindexhintbundle 
Obsidian
  • 3,719
  • 8
  • 17
  • 30
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.

Fabiano
  • 413
  • 3
  • 10