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.
*/1in 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.