Good day to all!
I use Symfony 3 and Doctrine in my project. The task is to process a large amount of data and for each element of this volume to update the information in the database. Accordingly, there is a foreach loop of this type:
foreach ($array as $item) { $entity = $em->getRepository('AppBundle:Model')->find($id); $entity->setParameter($value); $entity->flush(); } The fact is that after each iteration of the cycle, the amount of memory used grows and if the number of elements in the processed array is about tens of thousands, the memory usage rises even to gigabytes.
Read, including on the English-language StackOverflow, about the use of structures
- $ em-> clear ();
- $ this-> em-> getConnection () -> getConfiguration () -> setSQLLogger (null);
- gc_collect_cycles ();
But none of this helps, and the memory still increases with each iteration. I hope for your help and thank you in advance!