list->mysql query iteration for cron job


/ Published in: PHP
Save to your folder(s)

I needed to have a cron job that did some MySQL work iterating through a long list of items based on the content of a table in MySQL. I wanted each item in the table to be iterated over roughly once every 5 minutes, but building up the in-memory list of items to be processed based on the full contents of the table (~100 rows) was killing server memory and the process was dying. I wanted to find a way to, based on the time, only process a segment of the table's results, and to be reasonable confident that they would all be processed approximately every 5 minutes.

Really simple problem, actually, but it took me a while to find the right logic...

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.