Guest User

Untitled

a guest
Jul 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. require_once "bootstrap.php";
  3. $pdo = $entityManager->getConnection()->getWrappedConnection();
  4. $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
  5. $queryBuilder = $entityManager->createQueryBuilder();
  6. $queryBuilder->select('product.id,product.name as productName,owner.name as ownerName')
  7. ->from(Product::class, 'product')
  8. ->leftJoin(ProductOwner::class,'owner','WITH','owner.id = product.productOwner');
  9. ;
  10. $query = $queryBuilder->getQuery();
  11. $query->setMaxResults(405000);
  12. $iterableResult = $query->iterate(null,\Doctrine\ORM\Query::HYDRATE_ARRAY);
  13. foreach ($iterableResult as $row) {
  14. $product = array_pop($row);
  15. echo '#' . $product['id'];
  16. echo $product['productName']; echo ' ';
  17. echo ' (' . $product['ownerName'] . ')';
  18. echo " - ". getMemoryUsage();
  19. echo "\n";
  20. }
  21. // with 400k rows this consumes a constant 6 MB
  22. // this is because doctrine loads the results into the memory one by one and we do not use objects
Add Comment
Please, Sign In to add comment