I've got a drush script that's used to clear out old, unpublished nodes that have come in from feedapi. The script is fairly simple: get all the nodes with status 0 of a certain type ("post") and age (older than 90 days), loop through them, delete each one.

The script runs through about 4,000 nodes at a time, then exhausts the memory available to its PHP process. I can watch the script's footprint grow from top and the 4,000 node limit is somewhat consistent. I've got over 100,000 nodes to work through, though, so I don't think it will be practical to just jack up the RAM available to the process long enough to get a run out of it.

Is there anything I can add at the bottom of each iteration to release the RAM it's consuming?


Other Options: http://groups.drupal.org/node/189694


You could use the Drupal batch API and call it from Drush. You could use the Drush batchTest unit test as another reference on how to use the batch API from Drush.


How about getting only a fraction of the nodes at a time from the DB, say 3000 at a time, using SQL's LIMIT (and OFFSET) commands in your SELECT query? Then simply loop over those "chunks".

Not the answer you're looking for? Browse other questions tagged or ask your own question.