Greetings, I am developing a web app. One piece of it will allow users to schedule a “reminder” email to be sent to them at a particular time of day. What is the best way to accomplish this? Basically, all the solutions I’ve come up with operate on a “polling” pattern when what I want is an “interrupt” pattern.
Here are some possible solutions I’ve come up with:
-
Have a cronjob fire every minute. The script that fires checks a database to see if there are any emails to send, if there are, it sends them, else it goes back to sleep. Drawback with this is that there is a bit of overhead incurred every minute. Also, this may not be a scalable system, especially when the number of users gets so large that it may take over a minute to send out all the emails.
-
Same as #1, but job only fires every 15 minutes. This is a bit more manageable, but not perfect, as it restricts the users to reminders on the 15 minute marks, and it still incurs a bit of overhead when there are no emails to send. Not bad, but not perfect either.
-
Have PHP exec() a bit of code that dynamically alters crontab or schedules an “at” job in the underlying linux. This would give me the flexibility and “interrupt” type model I so crave, but would open up a huge security hole in allowing PHP to exec() linux code. So, I’m going to go ahead and rule this one out.
So, anything better than what I’ve come up with? Perhaps a way to schedule email without using cron? I’m very curious to see what you guys have to say about this :).
Use first variant.
And don’t think about overhead – not in this case.