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)
{
}
}