I have a DB with 2 tables:
subscribers:
_____________________________
| id | name | email |
|________|________|___________|
| 1 | John | e@m.com |
| .. | .. | .. |
| 5000 | Mark | c@b.com |
|________|________|___________|
last_id:
_______
| id |
|_______|
| NULL |
|_______|
Every day I run a cron job to send all the emails at once, But The script is timing out after 100 sec.
So instead I'm thinking of sending about 200 emails per time:
/* Get the id from last time is script was executed */
$last_id = "SELECT `id` FROM `last_id`";
/* Select the next 200 subscribers starting from the last id */
$query= "SELECT * FROM `subscribers` WHERE `id` > ". $last_id . " LIMIT 200";
/* Send 200 emails */
..
/* Get the last id of these 200 subscribers */
$last = ;
/* Update the value of `id` in `last_id` table */
$query= "UPDATE `last_id` SET `id` = ". $last;
The cron job runs this script every 10 minutes, But after sending all the emails the script would be executed over and over without sending any emails.
So how to stop executing this cron job after all the emails are sent, When last_id
= 5000
and start it again the next day?