public function createPerson($peopleToAdd) { // Define the size of record, the frequency for persisting the data and the current index of records $batchSize = $this->getBatchSizePersonManager(); $i = 1; if (!empty($peopleToAdd)) { foreach ($peopleToAdd as $id => $name) { $tmdbPerson = $this->getTmdbPerson($id); $person = new Person(); $person->hydrate($tmdbPerson); $this->persist($person); // Each x import persisted we flush everything if ($i % $batchSize === 0) { $this->flush(); $this->clear($person); } $i++; } } }