在 30 秒的执行时间内可以使用多少 mail() 函数?
我必须创建一个页面,向时事通讯订阅者发送电子邮件。有超过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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
php
max_execution_time
设置是可定制的。30
秒是默认值,但您可以将其设置为0
秒,从而完全没有执行时间限制。使用 set_time_limit()。如果您这样做,您应该能够发送所有电子邮件。
请注意每秒向同一邮件服务器发送多于一封电子邮件。您不想被列入黑名单。
The php
max_execution_time
setting is customizable.30
seconds is the default but you can set it to0
seconds for no execution time limit at all. Use set_time_limit().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.
您应该从 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.
这取决于太多的变量,不可能有单一的答案。因素包括:
的唯一方法就是尝试。
That depends on so many variables that a single answer is not possible. Factors include:
The only way to find out is to try it.
不久前我在我的一个项目中遇到了这个问题。解决方案是将发送的电子邮件与实际站点隔离。
我编写了一个小类,该类将被调用来发送电子邮件。它将传递一封模板化电子邮件,然后将其存储到数据库的邮件队列中。在后端,我有一个 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.
说真的,如果您想从普通邮件应用程序向十个人发送相同的邮件,您通常会创建十封相同的邮件,还是在将收件人添加到发送列表后发送邮件?
编辑:如果答案是“我发送一次”,我认为您也应该在这里朝这个方向看(甚至描述了如何发送给多个收件人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)