/ Published in: PHP
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...
Really simple problem, actually, but it took me a while to find the right logic...
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$min = ( 20 * ( $x - 1 ) ) + 1; //gets 1, 21, 41, 61, 81 $max = ( 20 * $x ); //gets 20, 40, 60, 80, 100 $feedListSql = quotesmart( "SELECT DISTINCT id, feed_url FROM {$this->feedTable} WHERE active = 1 AND id >= {$min} AND id <= {$max}" );