Created
February 13, 2017 10:21
-
-
Save webdevilopers/a0c7e16a416fa6d99ee8064b1f8f887b to your computer and use it in GitHub Desktop.
OutOfMemoryException in PDOConnection using Doctrine iterate result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 7041 rows with content being BLOB content - total table size ~ 2.4 GB | |
$instructionRepository = $this->getDoctrine()->getRepository('PlusquamContractBundle:Instruction'); | |
$instructionQueryBuilder = $instructionRepository->createQueryBuilder('i') | |
->where('i.content IS NOT NULL') | |
->orderBy('i.id', 'desc'); | |
$instructions = $instructionQueryBuilder->getQuery()->iterate(); | |
?> |
Maybe this helps: http://stackoverflow.com/a/27186091/693546
You made my day @mablae!
Indeed changing the USE_BUFFERED_QUERY attribute on PDO prevents loading anything into memory:
$pdo = $this->getDoctrine()->getManager()->getConnection()->getWrappedConnection();
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$sql = "SELECT i.id FROM instructions AS i WHERE i.content IS NOT NULL";
$em = $this->getDoctrine()->getManager();
$stmt = $em->getConnection()->prepare($sql);
$stmt->execute();
$instructionIds = $stmt->fetchAll();
I also tried using the repository too. But it looks like the Manager then does not recognize my attribute change then?
$pdo = $this->getDoctrine()->getManager()->getConnection()->getWrappedConnection();
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$instructionQueryBuilder = $instructionRepository->createQueryBuilder('i')
->where('i.content IS NOT NULL')
->orderBy('i.id', 'desc');
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to use raw SQL too:
Againg: memory exhausted!