用php延迟邮件发送
我正在使用 FOR 循环从数组 [250] 发送电子邮件。
for ($counter = 0; $counter <= 250; $counter ++){
// send email function[$counter]
}
我考虑过 sleep() 函数,但由于服务器有限制执行时间,所以不是一个选择。 请帮我解决这个问题!
I'm using a FOR loop to send emails from an array[250].
for ($counter = 0; $counter <= 250; $counter ++){
// send email function[$counter]
}
I thought about the sleep() function but since the server have limit excute time isn't an option.
Please help me with this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然(未经测试)sleep 函数夺走了 php 的控制权,因此最大执行时间不适用。
来自: http://www.hackingwithphp.com/4/11/0 /pausing-script-execution
"请注意,默认的最大脚本执行时间是 30 秒,但是您可以使用 sleep() 和 usleep() 使脚本执行的时间更长,因为从技术上讲 PHP 没有期间控制睡眠操作。”
Apparently (untested) the sleep function takes control away from php so the max execution time does not apply.
From: http://www.hackingwithphp.com/4/11/0/pausing-script-execution
"Note that the default maximum script execution time is 30 seconds, but you can use sleep() and usleep() to make your scripts go on for longer than that because technically PHP does not have control during the sleep operation."
使用 cron - 几乎所有主机都允许您使用它(免费主机除外),如果您需要帮助,他们应该非常乐意帮助您设置它(如果他们不能帮助您,请不要向他们提供您的信息)钱)
Use cron - almost all hosts let you use it (except the free-host ones) and they should be more than happy to help you set it up if you need assistance (if they don't help you, don't give them your money)
要延迟循环发送电子邮件,您可以创建自己的 wait() 函数,其中包含一个循环,并在迭代之前调用它。如果您想等待的原因是为了避免 ISP 出现问题,请阅读以下答案:
发送群发使用 PHP 发送电子邮件
To delay sending emails in a loop, you can create your own wait() function with a loop inside it and call it before iterating. If the reason you want to wait is to avoid problems with an ISP then read this SO Answer:
Sending mass email using PHP
如果没有某种调度程序,您总是会达到执行限制。
您可能希望将电子邮件存储在数据库中,然后让 cron 执行它们。
或者您可以延长执行时间:
为什么您仍然需要延迟它们?
Without some kind of scheduler you're always going to hit your execution limit.
You may want to store the emails in a database then have cron execute them.
Or you can up your execution time:
Why do you need to delay them anyways?