Last active
August 29, 2015 14:07
-
-
Save mikedfunk/4c92ffdbc31785732b0c to your computer and use it in GitHub Desktop.
Go through queries in chunks so you don't run out of memory
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 | |
$offset = 0; | |
// only process 1000 at a time | |
$increment = 1000; | |
// getByOffsetAndLimit is the key factor here! | |
while ($galleries = $this->listingGalleryRepository->getByOffsetAndLimit($offset, $increment)) { | |
// we have to break out of the loop if there are no more left | |
if (count($listingGalleries) === 0) { | |
break; | |
} | |
foreach ($galleries as $gallery) { | |
// do something with each gallery in this chunk... | |
} | |
// update the offset by the chunk increment | |
$offset += $increment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment