We have an internal ESP that uses third party SMTP (Dynect) to send our emails out. Once the scheduled sendjob is picked up by the cron job it builds an array of all the member emails that need to be sent to. Once it has completed that, it creates the SMTP connection and begins to loop through the array sending one email at a time (we can't batch because we have dynamic fields that need to be populated for each email going out).
If the job needs to be paused or un-paused I initiate the creation of a flag file that is checked for each time through the loop:
if(file_get_contents($filename) == "STOP")
As you can see, there are two states of the flag file. If the file contains "STOP", it initiates the deletion of the sendjob. If the file is simply present but without "STOP" than it is a pause file and the script sleeps for 10 seconds before checking again.
Now my question is that I am now being asked to be able to set a limit of emails being sent per hour. Would I use a flag file as well or is there another method I could use? I don't want the jobs to stop completely, I just want them to pause if our hourly limit has been met and then start up again in the next hour until the threshold is reached again. My only concern is having all the processes sleeping at once. In one hour we may have 10 to 15 jobs sending at once and I want an overall limit set.
Overall how many emails are you sending and at what rate now? Are your scripts sleeping between outgoing emails?