Answer the question
In order to leave comments, you need to log in
How is EntityManager->clear() different from Doctrine->resetManager()?
There are several services on the symphony that listen to RabbitMQ (respectively, the services spin in an endless loop).
Of course, in such cases, you need to clear the EntityManager cache so that php does not crash with a memory limit.
In some services, this is done through EntityManager->clear(), in others, through Doctrine->resetManager()
At first glance, it seems that the same thing is done, but, in services with EntityManager->clear(), they still periodically fall with a limit memory.
Looked at the code of these methods:
public function clear($entityName = null)
{
if ($entityName !== null && ! is_string($entityName)) {
throw ORMInvalidArgumentException::invalidEntityName($entityName);
}
if ($entityName !== null) {
@trigger_error(
'Calling ' . __METHOD__ . '() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0.',
E_USER_DEPRECATED
);
}
$this->unitOfWork->clear(
$entityName === null
? null
: $this->metadataFactory->getMetadataFor($entityName)->getName()
);
}
public function resetManager($name = null)
{
if ($name === null) {
$name = $this->defaultManager;
}
if (! isset($this->managers[$name])) {
throw new InvalidArgumentException(sprintf('Doctrine %s Manager named "%s" does not exist.', $this->name, $name));
}
// force the creation of a new document manager
// if the current one is closed
$this->resetService($this->managers[$name]);
return $this->getManager($name);
}
Answer the question
In order to leave comments, you need to log in
I remembered that the flow in the Doctrine can be due to the SQL Logger, which is in the Connection
When you do resetManager()
- you kill this SQL Logger with its objects in memory
You need to do something like
$this->em->getConnection()->getConfiguration()->setSQLLogger(null);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question