Joined March 2015
·

Anna Filina

Montreal
·
·

I would add a few things.

The detach() step is not necessary, since clear() does that for all entities currently tracked by Doctrine.

I like to flush() then immediately gc_collect_cycles() every X objects in a loop as that keeps the memory usage somewhat constant. Here's an example:

gc_enable();
foreach ($objects as $i => $obj) {
    $em->persist($obj);
    // change 500 depending on object size and available memory
    if ($i % 500 == 0) {
        $em->flush();
        gc_collect_cycles();
    }
}
// Once more for the remainder.
$em->flush();
gc_collect_cycles();
Achievements
1 Karma
0 Total ProTip Views
Interests & Skills