Closed lukepass closed 3 years ago
I think this is caused because Gaufrette's filesystem keeps every file it opens in a registry. Also, whenever contents are written these contents are saved in memory.
I solved this by calling $this->getFilesystem()->clearFileRegister();
in an override of FileProvider->setFileContents()
. Perhaps Sonata Media Bundle can call $this->getFilesystem()->removeFromRegister();
in FileProvider->setFileContents()
.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
thank you @jorrit , you saved my day, in fact you inspired me to get my solution without overriding anything, i just get the "sonata.media.provider.image"
by Dependency Injection, and i use it like this :
<?php
namespace App\Command\ACME;
use Sonata\MediaBundle\Command\BaseCommand;
use Sonata\MediaBundle\Provider\ImageProvider;
class MyCommand extends BaseCommand
{
private $sonataImageProvider;
public function __construct(ImageProvider $sonataImageProvider)
{
parent::__construct();
$this->sonataImageProvider = $sonataImageProvider;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ($variable as $key => $value) {
// ...some business logic ...
$this->entityManager->persist($someEntity);
$this->entityManager->flush();
// and here is the solution
$this->sonataImageProvider->getFilesystem()->clearFileRegister();
}
}
}
Environment
Symfony 3.4 website and console command
Sonata packages
Symfony packages
PHP version
Subject
Hello, I have a long-running command which imports a list of products (about 50,000) and each product can have more than one image.
There are a lot of media creations using this code:
I noticed that after a while my command starts consuming a lot of memory. I am using a lot of best practices when importing products, taken directly from the Doctrine website:
If I comment the persist of media, the used memory stays stable and I don't have any leaks.
Using a profiler (I'm not so sure about this), it seems that the culprit are the postPersist events generated by the media creation, probably the resizer configured in the config.yml are consuming a lot of memory and leaving leaks somewhere?
Is there something I can do about this?
This is an image taken from the profiler:
Thanks!