5

When I put a large image folder in my /web folder, the "cache"clear" command fails with a

"OutOfMemoryException"

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 151552 bytes) in /Users/john/Development/git/website/vendor/twig/twig/lib/Twig/Compiler.php on line 124

[Symfony\Component\Debug\Exception\OutOfMemoryException]                                  
Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 151552 bytes)  

Exception trace:
() at /Users/john/Development/git/website/vendor/twig/twig/lib/Twig/Compiler.php:124

The image folder contains 10.000 images and is about 600MB big. When I delete this folder, the "cache:clear" command runs successfully.

I'm using Symfony 2.8 with PHP 7.1. The PHP memory limit is set on 512MB, which is the maximum on my hosting.

Update:

When I add --no-warmup to the command, I don't get the exception.

$ php app/console cache:clear --verbose --no-warmup
Muhammad Saad
  • 713
  • 1
  • 9
  • 31
BigJ
  • 1,990
  • 2
  • 29
  • 47
  • What if you'd change the location of your images? You could create a folder 'private' besides the 'public' one. That should not be copied to web. But then you'd need some extra work to access the images. – KhorneHoly Dec 14 '17 at 11:34
  • 1
    @BigJ Worth reporting in the Symfony issue tracker, 2.8 is only 1 month beyond support. I can't think why Twig is wanting to scan all your assets unless it's to do with Assetic? – PeterB Dec 14 '17 at 11:38

2 Answers2

3

You can limit the usage of the php command like this:

php -d memory_limit=512M app/console cache:clear --verbose --no-warmup

Hope this works for you :)

Jasson Rojas
  • 299
  • 3
  • 12
  • 1
    This works, thanks! Although the huge resource consumption looks like a bug in the cache warm-up. – BigJ Dec 19 '17 at 23:59
-2

What you could do is changing the memory_limit by ini_set('memory_limit', '-1'); but this is NOT a solution at all.

Please don't do that. Obviously php has a memory leak somewhere and you are telling the server to just use all the memory that it wants. The problem has not been fixed at all. If you monitor your server, you will see that it is now probably using up most of the RAM and even swapping to disk.

You should probably try to track down the exact bug in your code and fix it.

  • In theory that could fix the problem, but how much memory would be needed? 512MB is already a lot for PHP to have. – BigJ Dec 14 '17 at 11:39
  • Yes, well it's clear that your code has a memory leak. What you could do is changing the memory_limit by ini_set('memory_limit', '-1'); but this is NOT a solution at all. Please don't do that. Obviously php has a memory leak somewhere and you are telling the server to just use all the memory that it wants. The problem has not been fixed at all. If you monitor your server, you will see that it is now probably using up most of the RAM and even swapping to disk. You should probably try to track down the exact bug in your code and fix it. – Matthijs Otterloo Dec 14 '17 at 11:40
  • I don't think my code is the problem, because when I delete the image folder, the problem goes away. This is just a image folder on my hosting, I don't even access the images with asset(). – BigJ Dec 14 '17 at 11:42