Skip to content

Instantly share code, notes, and snippets.

@mikedfunk
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedfunk/4c92ffdbc31785732b0c to your computer and use it in GitHub Desktop.
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
<?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