使用PHP,我有一个查询,该查询遍历数据库,以在一天中的特定时间查找具有提醒触发器的待处理任务.我有一个cronjob,它每10分钟运行一次,并检查数据库中是否有将"remind_me"字段设置为在接下来的10分钟内关闭的行.如果确实找到了什么,什么是将包含任务信息的电子邮件排队的最佳方法是什么?
Using PHP, I have a query that goes through my DB looking for pending tasks with reminder triggers at certain times of the day. I have a cronjob that runs every 10 mins and checks the DB for any rows that has "remind_me" field set to go off within the next 10 mins. If it does find something, what's the best way to queue an email with the task information?
我想我需要某种消息队列系统,但是电子邮件部分如何工作?我是否需要另一个每分钟运行一次的cronjob来检查队列系统?
I guess I'll need some sort of message queue system, but how does the email part work? Will I need another cronjob that runs every minute to check the queue system?
推荐答案如果您想做一个邮件队列系统,我建议您看一下 PEAR :: Mail_Queue 和相关的教程.
If you want to do a mail queue system I would suggest you take a look at PEAR::Mail_Queue and the associated tutorial.
您可以在运行10分钟脚本时使邮件排队,并可以通过cron作业每10分钟清空一次邮件队列.您还可以每分钟清空一次邮件队列,并在有问题的邮件队列中实施不发送之前"的时间.
You would be able to queue up mail when your 10minute script ran, and have the mail queue emptied every 10 minutes via a cron job. You could also have the mail queue emptied every minute and implement a 'do not send before' time in the queue on the mail in question.
或者,您可以每分钟运行一次检查脚本,以检查最近十分钟内是否有提醒事项,然后立即发送邮件,从而无需队列系统.
Alternatively you could run your checking script every minute checking for items that a reminder is due in the last ten minutes and send the mail immediately, which removes the need for a queue system.
这可以通过记录上次发送警报的时间来实现(这样您就不会错过任何警报,也不会两次发送警报)
This could be implemented by a record of when you last sent alerts (so that you don't miss any and don't send alerts twice)
希望有帮助.
更多推荐
如何安排发送电子邮件
发布评论