最佳方法是动态计划提醒电子邮件?什么比cron好? [英] Best way to dynamically schedule reminder email? Anything better than cron?

查看:173
本文介绍了最佳方法是动态计划提醒电子邮件?什么比cron好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,我正在开发一个网络应用程序。其中的一部分将允许用户安排在一天的特定时间发送提醒电子邮件给他们。什么是最好的方法来完成这个?基本上,我想出的所有解决方案操作在轮询模式,当我想要的是一个中断模式。

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:


  1. 每分钟都有cronjob的火。触发的脚本检查数据库以查看是否有要发送的电子邮件,如果有,则发送它们,否则返回睡眠。缺点是每分钟都有一点开销。此外,这可能不是一个可扩展的系统,特别是当用户数量过多,可能需要一分钟才能发出所有电子邮件。

  1. 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.

与#1相同,但作业仅每15分钟触发一次。这是一个更易于管理,但不完美,因为它限制用户提醒在15分钟的标记,它仍然会产生一点开销,当没有电子邮件发送。

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.

有PHP的exec()一些代码动态地改变crontab或调度一个在工作在底层的Linux 。这将给我灵活性和中断类型模型我这么渴望,但会打开一个巨大的安全漏洞允许PHP exec()linux代码。

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.

所以,任何比我的出来了?也许一种方法来计划电子邮件而不使用cron?我非常想知道你们对这个问题的看法:)

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 :).

推荐答案

使用第一个变体。


可能需要一分钟才能发出
所有电子邮件

it may take over a minute to send out all the emails




  1. 检查,如果file_exists('mailing.q');如果仍然存在 - 终止执行。

  2. 创建文件mailing.q

  3. 发送电子邮件

  4. 取消链接('mailing.q');

  1. Check, if file_exists('mailing.q'); If still exists - terminate execution.
  2. Create file mailing.q
  3. send emails
  4. unlink('mailing.q');

不要考虑开销 - 在这种情况下不需要。

And don't think about overhead - not in this case.

这篇关于最佳方法是动态计划提醒电子邮件?什么比cron好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆