Symfony 5 cache:clear php.CRITICAL: Fatal error: Allowed memory size
Asked Answered
G

2

6

I am encoutering the following error with Symfony 5 when trying to

bin/console cache:clear

I know how I could patch that (memory_limit=-1) but I want know why I have this error.

Error :

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32230840 bytes) in /Applications/MAMP/htdocs/Toile./vendor/twig/twig/src/Lexer.php on line 157

15:50:13 CRITICAL [php] Fatal Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32230840 bytes)

[
  "exception" => Symfony\Component\ErrorHandler\Error\OutOfMemoryError {
    -error: [
      "type" => 1,
      "message" => "Allowed memory size of 134217728 bytes exhausted (tried to allocate 32230840 bytes)",
      "file" => "/Applications/MAMP/htdocs/Toile./vendor/twig/twig/src/Lexer.php",
      "line" => 157
    ]
    #message: "Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32230840 bytes)"
    #code: 0
    #file: "./vendor/twig/twig/src/Lexer.php"
    #line: 157
  }
]

In Lexer.php line 157: Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32230840 bytes)

I am unable to track from where this error comes from.

I removed all twig templates from my project, I clearing the cache manually but nothing .. Any idea?

Thanks

Galileo answered 6/1, 2020 at 16:27 Comment(2)
If it takes too much memory that's, because it takes too much memory so nothing you can do beside increasing the limit in the php.ini or via the command line, eg. php -dmemory_limit=1G bin/console ca:clLorenelorens
Thanks, I increasing the limit in the php.ini to 256MOGalileo
G
3

It looks like the bin/console cache:clear command takes up a lot of memory. I don't think it's because of the twig files.

setting up memory_limit=-1 is sort of you are disabling the memory limit, means giving unlimited of memory to run PHP. Please check your php.ini file and adjust the memory_limit.

Note that you might have 2 php.ini files for PHP, one for web and one for command-line use. Use php -i to see the loaded ini file.

Use this command php -i | grep 'Configuration' to grep the output from command line.

Genu answered 7/1, 2020 at 8:4 Comment(3)
Thanks, I was already doing that, but I wanted a better solution. I finally increased the memory_limit of php.ini to 256MB.Galileo
It's not a solution, you just removed the problem at all. Why there is a need to allocate more memory when you are purging sth? This is the root cause whom you just ignored.Arterial
It's not a valid anwser, so. No permanent solution has been proposedAgglutinogen
E
0

Check all your Project Directory if some of code doesn't contain any lines like this: ini_set('memory_limit' — Symfony parses all classes and takes into account it. For example, in my case there was: ini_set('memory_limit', '42M'); and 42MB was not enough to run console task.

Erst answered 10/8, 2022 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.