Reputation: 872
I try to run this command to build model in my symfony project(1.4) :
php symfony propel:build-model( or all )
I have this error :
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 20 bytes) in /home/sfprojects/jobeet/lib/vendor/symfony/lib/util/sfClassManipulator.class.php on line 176
I searched before asking people here so I changed memory_limit = 64M
in my php.ini to 128M , 510M , 1024M ...
but I have the same error that really get me crazy!
I'm using Ubuntu with apache2,php5...
Upvotes: 4
Views: 25716
Reputation: 11
I add this comment here because this is the second page that pops out for the search term "Php symfony: Fatal error Allowed memory size of xx bytes exhausted".
I recently encountered this issue with Symfony 6.3.7
. It takes me a couple of days to solve because I didn't find the right resource on the internet that could help.
In general, increasing the memory_limit
is not the best solution (btw, I've set mine to -1 and increased the max_x_time, but nothing). You'll need to investigate to find the root cause of the issue.
For me, the $kernel->handle($request)
; in public/index.php could not terminate its execution or throw an error, therefore there were no symfony dump/log neither in the CLI nor in the browser, I just got HTTP ERROR 500
from the browser. I've followed the $kernel->handle function until PhpDumper.php
in vendor with a bunch of dumps and then used git diff
.
It turns out there were a circular reference exception
that has not been detected/controlled by the ServiceCircularReferenceException
and I have no idea why. I tried to reproduce the same error with Symfony 5.4, Symfony 6.3.8, and it has been properly handled.
Finally, thanks to git diff, I removed the dependency injections that led to the endless recursion and everything is now running smoothly with just 128M of memory
.
Code example for my case(all projects on debug mode
):
Service2 calling Service1.
<?php
namespace App\MyModule\Service;
use App\Service\XService\Service1;
class Service2
{
public function __construct(private Service1 $service1)
{
}
}
Service1 calling Service2
<?php
namespace App\Service\XService;
use App\MyModule\Service\Service2;
class Service1
{
public function __construct(private Service2 $service2)
{
}
}
Upvotes: 1
Reputation: 26
You should avoid putting dump in loops in your
Controllers
or in your twig templates with
{% for row in rows %}
{{ dump(row) }}
{% endfor %}
Upvotes: 1
Reputation: 918
Edit: Sorry, this was meant as a response to How can I increase the allowed memory size in Symfony? (I had both open at the same time.)
You probably have something like this in your composer.json:
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
Replace it by
"scripts": {
"auto-scripts": {
"php -dmemory_limit=512M bin/console cache:clear": "script",
Upvotes: 2
Reputation: 11
Install Symfony from the oficial page.
symfony composer update
symfony composer = Runs Composer without memory limit
Upvotes: 0
Reputation: 863
Make sure you edited your php.ini
file for php-cli and not for Apache.
In /etc/php5/cli/php.ini
for your Ubuntu.
Upvotes: 6
Reputation: 350
Try putting:
<?php ini_set('memory_limit', '3G'); ?>
at the top of your ./symfony file.
Upvotes: -3
Reputation: 978
However this wont probably solve it, in your .htaccess of your project root folder (/web), add the following line:
php_value memory_limit 1024M
Pay attention to what Bruno-P already told you, make sure that you are already changing the right php.ini file for your symfony project. If you have more than one php installation its possible that you are changing an old file.
Make sure also you are typing it right in your php.ini:
Symfony 1.4: PHP Fatal error: Allowed memory size of 33554432 bytes exhausted
Clear symfony cache (symfony cc), close the web server and execute the command again:
symfony propel:build-model
You may also check your php configuration for your memory values limit set. Make a new file in your project with the content:
<?php
phpinfo();
?>
Upvotes: -1