I'm running a doctrine query in a loop, binding parameters and executing multiple times. The query executes fine, the problem is that the memory usage jumps up about 3mb per set of loops. It doesn't seem like garbage collection is kicking in and eventually the server runs out of memory.
foreach () { .....
foreach () { .....
$conn = $this->getEntityManager()->getConnection();
if ($this->sql == null) {
$this->sql = $conn->prepare(
"INSERT INTO table (l_id, a_id) VALUES (:lId, :aId);"
);
}
//Memory usage 200
foreach($lo as $l) {
$this->sql->bindParam('lId', $l->getId());
$this->sql->bindParam('aId', $aId);
$this->sql->execute();
}
//Memory usage ++3mb
}
}
This entire script is also nested within a loop. So it will get called many many times. But the foreach loop above seems to be where the memory increases.
I'm calling straight inserts to the database, so the entity manager isn't even used as initially I thought this could be slowing it down.
Edit: I've tried changing bindParam to bindValue but the same issue occurs. and moving the second bindParam outside the loop;