I have a requirement to run a server script on scheduled times entered by the user. This is for a program for scheduling emails. A user can enter the specific times when they want to send the mail. I have a table which stores the userid, the email text and the time at which the mail is to be sent. This time is defined in minutes. I don’t want to do it through a cron job as it would mean running cron jobs every minute. Is there a way to do this that is more machine efficient – maybe through database triggers or something. Any help is appreciated.
Thanks
Vinayak
If all your cron job is doing is a quick query to check if any mail is scheduled to send, then it’s not going to be an expensive operation to run each minute. It should be less load on your server than a typical page load (which usually requires quite a few queries, and more).
Use a script run by a cron job, but make sure that it is as lightweight as possible. From what you describe, you should be able to get it down to one simple query that – most of the time – returns zero results. That’s fairly lightweight.