PHP睡眠功能(电子邮件调节)冻结整个服务器 [英] PHP Sleep Function (Email Throttling) Freezes Entire Server

查看:160
本文介绍了PHP睡眠功能(电子邮件调节)冻结整个服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个标准的共享Hostgator,每小时限制500封邮件。



我正在尝试限制我的电子邮件脚本,每8个发送一封电子邮件秒...

  $ query = mysql_query(SELECT email FROM users WHERE verified ='1'ORDER BY balance DESC) ; 
while($ arr = mysql_fetch_array($ query)){
set_time_limit(30);
$ mail-> AddAddress($ arr [0]);
$ mail-> Send();
$ mail-> ClearAddresses();
echoSent to。$ arr [0]。< br>< br>;
sleep(8);
}

我正在使用PHPMailer。脚本本身工作正常,每8秒发送一次电子邮件...



但是域的其他部分完全冻结。



有没有另一种睡眠方法,我可以使用它不会冻结我的整个域?



谢谢:)

解决方案

Cronjobs不能二次执行,只能微不足道。分钟栏中的 * / 1 将每1分钟运行一次脚本,但您不能再获得更多的细节。



睡眠没有任何问题,但不要从浏览器运行命令。你锁定域名的原因是因为你的Apache线程在脚本中被保持在睡眠状态。在完成之前,您的请求将被阻止并排队。



我建议你保留你的脚本,只需要每小时或每隔几个小时执行一次cronjob。它需要多长时间运行一次?每天一次?



下面将在午夜后5点运行,并将其扔到后台。

  5 0 * * * user php -f / path / to / file& 


I am on a standard shared Hostgator which has a limit of 500 mails per hour.

I am trying to throttle my email script to only send 1 email per 8 seconds...

$query=mysql_query("SELECT email FROM users WHERE verified='1' ORDER BY balance DESC");
while($arr=mysql_fetch_array($query)){
set_time_limit(30);
$mail->AddAddress($arr[0]);
$mail->Send();
$mail->ClearAddresses();
echo "Sent to ".$arr[0]."<br><br>";
sleep(8);
}

I am using PHPMailer. The script itself works fine, it emails once every 8 seconds...

But the rest of the domain freezes up completely.

Is there an alternative method of sleeping I can use that won't freeze up my whole domain?

Thanks :)

解决方案

Cronjobs cannot be executed secondly, only minutely. */1 in the minute field will run the script every 1 minute, but you cannot get any more granular than that.

There is nothing wrong with the sleep, but do not run the command from your browser. The reason you are locking up the domain is because your Apache thread is held up on the script with sleep. Until it finishes, your requests will be blocked and queued.

I would suggest that you keep your script, and just execute it with a cronjob hourly, or every few hours. How often does it really need to run? Once a day?

The below will run it every night at 5 after midnight, and throw it to the background.

5 0 * * * user php -f /path/to/file &

这篇关于PHP睡眠功能(电子邮件调节)冻结整个服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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