Reputation: 481
I create a custom console command in symfony2. This command will call the api to find fit jobs for all users. then I'll get a error like this. My code is like:
$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$user = $em->getRepository('EnsUserBundle:User')->findAll();
foreach ($user as $user)
{
.....
$em->flush();
}
}
}
Then I want to clear the entitymanager for each user.
$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$user = $em->getRepository('EnsUserBundle:User')->findAll();
foreach ($user as $user)
{
.....
$em->flush();
$em->clear();
}
}
}
It will lead to a error:
Then i try to use the batch process:
$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
$user = $em->getRepository('EnsUserBundle:User')->findAll();
$iterableResult = $em->getRepository('EnsUserBundle:User')->findAll()->iterate();
while (($row = $iterableResult->next()) !== false)
{
foreach ($user as $user)
{
.....
$em->flush();
$em->clear();
}
$em->detach($row[0]);
}
}
But it leads to an error
So, do you have any good advices? Thank you !
Upvotes: 0
Views: 2281
Reputation: 8855
You could try :
Increase the maximum memory a script consumes inside php : php.ini
memory_limit = 512M
Flush your objects when it reaches XX items (ex: each 100 items). You can clear your manager each time you flush it.
Upvotes: 1