orm: Batch Processing ,out of memory
$q = $this->_em->createQuery('select u from MyProject\Model\User u');
$iterableResult = $q->iterate();
foreach ($iterableResult as $row) {
//nothing
$this->_em->detach($row[0]);
}
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to all
ocate 1425408 bytes) in C:\mmood\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\P
DOConnection.php on line 104
[Symfony\Component\Debug\Exception\OutOfMemoryException]
Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate
1425408 bytes)
Total: 4000,000 rows I tried the code and found that was out of memory
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (11 by maintainers)
worked for me
As a workaround, I ended up iterating over 10K rows at a time:
Ah yes, fairly sure that the ORM doesn’t lazily iterate over DBAL resultsets: that is a big issue that needs work.
It works perfectly
Try this, works for me
$conn = $emd->getConnection(); $conn->getWrappedConnection() ->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $conn->getConfiguration()->setSQLLogger(null);