title: How to Prevent PHP Allowed Memory Size Fatal Error from query result?
body: <p>I have a (cake) php function designed to update entries in a MySQL table; first of all it runs a query to get all the new items since a $lastImportDate, and then loops through performing various actions on the item, saving the item, saving related table information.</p>
  
  <p>Unfortunately this seems to be collapsing under the excessive weight of one particular request.  Here there are 5917 (and probably counting!) entries to update.  The function loops through for a while, but eventually dies with an "Allowed memory size of [lots of bytes] exhausted" error. </p>
  
  <p>Without forcing anyone to wade through extensive code - what strategies can I reasonably adopt to try to stop this memory leak from rendering this table un-updateable?  </p>