在 30 秒的执行时间内可以使用多少 mail() 函数?

发布于 2024-08-09 09:09:48 字数 313 浏览 2 评论 0原文

我必须创建一个页面,向时事通讯订阅者发送电子邮件。有超过14000名订户。我想使用 php mail() 函数向他们发送电子邮件。但我担心它无法在 php 30sec max_execution_time 限制内向所有订阅者发送电子邮件。无法通过向订阅者发送测试电子邮件来测试可以发送多少电子邮件。所以我想知道在 30 秒 max_execution_time 限制内使用 mail() 函数可以发送多少电子邮件。 如果您能回答我,将会非常有帮助。

还有一个问题-mysql执行时间也算在php中吗?

Apache 版本 2.2.13 (Unix) PHP 版本 5.2.11

I have to made a page which will send Email to Newsletter subscribers. There is more then 14000 subscriber. I want to use php mail() function to send Email to them. But I'm afraid that it will not be able to send email to all subscribers for php 30sec max_execution_time limit. Its not possible to test how much Email can be sent by sending Test Email to subscribers. So I want to know how much Email can be sent with mail() function in 30 second max_execution_time limit.
Will be very helpful if you can answer me.

also another question - Is mysql execution time is also count in php?

Apache version 2.2.13 (Unix)
PHP version 5.2.11

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

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

发布评论

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

评论(5

南冥有猫 2024-08-16 09:09:48

php max_execution_time 设置是可定制的。 30 秒是默认值,但您可以将其设置为 0 秒,从而完全没有执行时间限制。使用 set_time_limit()

set_time_limit(0);

如果您这样做,您应该能够发送所有电子邮件。

请注意每秒向同一邮件服务器发送多于一封电子邮件。您不想被列入黑名单。

The php max_execution_time setting is customizable. 30 seconds is the default but you can set it to 0 seconds for no execution time limit at all. Use set_time_limit().

set_time_limit(0);

If you do this, you should be able to send all your email.

Please be careful about sending more than one email to the same mail server per second. You don't want to get blacklisted.

谁与争疯 2024-08-16 09:09:48

您应该从 cronjob 运行它或生成后台任务或使用其他更适合批处理作业的东西。

如果您的邮件服务器足够快,您可能会在 30 秒内收到 14000 封电子邮件,但是当您获得更多订阅者并且它停止正常工作时会发生什么?

也许您可以在数据库中为每个用户设置一个标志,然后在后台任务发送他们的电子邮件时重置该标志。如果邮件服务器出现问题,这将有助于避免重复等情况。

You should run this from a cronjob or spawn a background task or use something else better suited to batch jobs.

You might get 14000 emails out in 30sec if your mailserver is fast enough, but what happens when you get a few more subscribers and it stops working properly?

Perhaps you can set a flag in the database for each user, then reset the flag as their email is sent by a background task. That will help to avoid duplicates and so on if there is a problem with the mail server.

妖妓 2024-08-16 09:09:48

这取决于太多的变量,不可能有单一的答案。因素包括:

  1. CPU 的速度
  2. 从发送系统到 MTA 的可用带宽
  3. MTA 接受电子邮件的能力 找出答案

的唯一方法就是尝试。

That depends on so many variables that a single answer is not possible. Factors include:

  1. The speed of the CPU
  2. The bandwidth available from the sending system to the MTA
  3. The MTA's capacity to accept emails

The only way to find out is to try it.

只怪假的太真实 2024-08-16 09:09:48

不久前我在我的一个项目中遇到了这个问题。解决方案是将发送的电子邮件与实际站点隔离。

我编写了一个小类,该类将被调用来发送电子邮件。它将传递一封模板化电子邮件,然后将其存储到数据库的邮件队列中。在后端,我有一个 cron 作业,每 X 秒调用一个邮件脚本。脚本查看数据库队列中的电子邮件,从队列中获取 X 个数字以尝试发送(按时间戳排序),然后尝试发送。假设没有抛出错误,脚本会将消息标记为已发送。下一步是从队列中清除所有已发送且超过 X 天的电子邮件(保留用于记录)。

希望这有帮助。

I had this exact problem a while back on one of my projects. The solution is to isolate the email sending from the actual site.

I coded a small class that would be called to send an email. It would be passed a templated email, which it would then store into the database in a mail queue. On the back end, I had a cron job that called a mailer script every X seconds. Script looks at the database queue for emails, grabs X number from the queue to attempt to send (ordered by timestamp in), then would attempt delivery. Assuming no errors were thrown, script would mark the message as sent. Next step would be to purge all emails from the queue that were sent and older than X days (kept for logging).

Hope that is helpful.

雨巷深深 2024-08-16 09:09:48

说真的,如果您想从普通邮件应用程序向十个人发送相同的邮件,您通常会创建十封相同的邮件,还是在将收件人添加到发送列表后发送邮件?

编辑:如果答案是“我发送一次”,我认为您也应该在这里朝这个方向看(甚至描述了如何发送给多个收件人http://www.php.net/mail)

Seriously, if you want to send the same mail to ten people from your normal mailapp, do you normally create ten identical mails or do you just send the mail once adding the recipients to the send list?

Edit: If the answer is "I send it once", I think you should look in that direction here as well (it is even described how to send to multiple recipients at http://www.php.net/mail)

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