1

我正在开发需要在预定时间发送电子邮件的网络应用程序。正确的场景是:如果邮件功能因任何原因失败,重试应在特定时间段后进行,直到邮件成功。所以这里的问题是,如果我在某处记录了邮件详细信息(这里是mysql db表),重试机制是如何实现的。这可以在不使用 cronjobs 的情况下实现吗?如果是,怎么做??

提前致谢。

4

4 回答 4

3

You'll need some kind of cron system anyway, but it could simply be a third party service calling a specific page on your site. Why don't you want to use cronjobs in the first place ?

Then your process would only be to log any failed attempt in a queue and treat the queue (= send mails) each x hours. You could also consider having a max number of retry or something like this.

于 2013-04-23T13:40:47.100 回答
0

您可以尝试创建一个包含无限循环的页面。这是完全未经测试的,我以前从未实施过这样的事情 - 这只是一个建议:

$hourToSend = 17; //this is the specified time to send (e.g. an hour, day, week..)

while(1)
{
    start:
    if(emailNotSent() == true && date('H') == $hourToSend) //boolean (function or variable) set after the email script has executed. could even be an array of email IDs.
    {
        resendEmail();
    }
    else
    {
        sleep(3600); //set an interval to check for failed emails, default = every hour
        goto start;
    }
}

这假设您可以访问具有良好正常运行时间的服务器,这不会受到始终打开一个浏览器窗口的影响(可能有利于监控、报告、日志记录等)。

+1 有趣的问题,欢迎提出意见和建议

于 2013-04-23T13:56:27.183 回答
0

If you have to use a scheduled time I would definitely use a cronjob. To make sure that e-mails are send just use a true/false loop which checks if its send or not.

于 2013-04-23T13:44:27.330 回答
0

对于电子邮件,您首先不应该使用 cron。任何有能力的MTA都应该能够对它无法发送的消息进行排队——这是一项要求

于 2013-04-23T14:08:24.293 回答