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

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:cl Commented Jan 7, 2020 at 8:10
  • Thanks, I increasing the limit in the php.ini to 256MO Commented Jan 7, 2020 at 11:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I was already doing that, but I wanted a better solution. I finally increased the memory_limit of php.ini to 256MB.
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.
It's not a valid anwser, so. No permanent solution has been proposed
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.