开发者

Delay email sending with php

开发者 https://www.devze.com 2023-04-06 14:38 出处:网络
I\'m using a FOR loop to send emails from an array[250]. for ($counter = 0; $counter <= 250; $counter ++){

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!


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


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:

<?php
   //replace 600 without how many seconds you need
   ini_set('max_execution_time', 600);

   ... loop through emails

?>

Why do you need to delay them anyways?


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."


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消