批量通过电子邮件发送mysql表设置?

发布于 2024-12-29 09:05:16 字数 654 浏览 5 评论 0原文

我为正在制作的简单批量电子邮件想出了一个架构。电子邮件发送者将通过运行 cron job 的 php 脚本每 5 分钟发送 X 封电子邮件。问题是我认为这不是最好的方法,并且正在寻找替代的更好的方法;或验证;)。

(简化的)架构如下所示:

 EmailList  |  JobQue  |   Jobs
------------|----------|----------
   email    |   jobid  |    id
            |   email  | esubject
                       |  ebody

这个想法是,当创建新作业时,它将其添加到 Jobs 表中,并且需要发送的每封电子邮件都将添加到 >JobQue 表。
然后,实际发送电子邮件的 cron'd php 脚本将循环遍历 JobQue 表中的下 X 个项目,发送并删除它们。

这是一个好方法吗?在中等负载下会弯曲吗? (1000-5000 封电子邮件,每天 1-5 个工作)?当然,如果有更多的电子邮件被添加然后发送,那么会出现这种情况,但是还会有其他问题吗(比如尝试一次性向表中添加 1000 条记录,即使我使用一个 mysql 查询将它们全部插入)?

谢谢,
最大限度

I came up with a schema for a simple batch email I'm making. The emailer will send out X number of emails every 5 minutes by running a cron job'd php script. The issue is that I don't think this is the best way to do it, and was looking for an alternate, better way; or validation ;).

The (simplified) schema would look like:

 EmailList  |  JobQue  |   Jobs
------------|----------|----------
   email    |   jobid  |    id
            |   email  | esubject
                       |  ebody

The idea is that when a new job is created, it adds it to the Jobs table, and every email that needs to be sent will be added to the JobQue table.
Then the cron'd php script actually sending the emails will just loop through the next X number of items in the JobQue table, send and delete them.

Is this a good way of doing it? Will it buckle under moderate load? (1000-5000 emails, 1-5 jobs a day)? Of course it would if there are more emails being added then sent, but would there be other issues (like trying to add a 1000 records to a table in one go, even if I'm inserting them all with one mysql query)?

Thanks,
Max

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浴红衣 2025-01-05 09:05:16

我认为这是一个非常有效的方法。唯一的问题可能是,如果您想一次发送数千封电子邮件。这可能会导致 php 超时。
用一个查询将数千条记录添加到mysql中还不错,在我看来这是最好的方法。
但我必须说,副本取决于查询本身。如果它太长(我的意思是字符串太长),那么您可能会失去与服务器的连接。
但我认为您对这个模式根本不会有任何问题。

I think this is a very effective way of doing it. The only issue could be, if you want to send like thousands of emails at once. It could lead to timeout in php.
Adding thousends of records into mysql with one query is not bad, it's the best way imo.
But I must say, the copy depends on the query itself. If it is too long (I mean a too long string), than you can loose the connection to the server.
But I don't think you will have any problems with this schema at all.

那一片橙海, 2025-01-05 09:05:16

至少,您可能需要考虑短于 5 分钟的 cron 时间。如果您将 X 限制为 30(这是避免被列入大量黑名单的关键数字),您的脚本将需要 16 小时 55 分钟才能完成 5000 封电子邮件。

At a bare minimum, you may want to consider a shorter cron time than 5 minutes. If you limited X to 30 (a key number for avoiding being listed on a lot of blacklists), you're script would take 16 hours and 55 minutes to complete 5000 emails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文