dhimok Posted June 12, 2007 Share Posted June 12, 2007 Hi everyone I want to send newsletters lets say to 1 000 subscribers. Any one can give me a start on how to send this in cycles by delaying it so that it wont time out? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/ Share on other sites More sharing options...
smc Posted June 12, 2007 Share Posted June 12, 2007 Well it won't timeout :\ PHP Scripts will only timeout if they are stuck on a function for your max execution time. I have one massive database transfer script that takes about an hour to execute , thank god its my server or I'd have some ticked off NAs Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273288 Share on other sites More sharing options...
chigley Posted June 12, 2007 Share Posted June 12, 2007 <?php $emails = array("email1@site.com", "email2@site.com"); $message = "This email was sent by PHP!"; $from = "noreply@mysite.com"; $subject = "Sent from PHP"; foreach($emails as $email) { $headers = "From: {$from}"; mail($email, $subject, $message, $headers); echo "Sent to {$email}<br />\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273290 Share on other sites More sharing options...
dhimok Posted June 12, 2007 Author Share Posted June 12, 2007 I have no problem sending the email. I was thinking more like lets say I must send 1000 emails so First I send 100 and then 100 and so on. Does the functions sleep() helps with this? sending 100 and then sleep(5) // 5 seconds and then start again with the next set of emails until they are done Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273302 Share on other sites More sharing options...
chigley Posted June 12, 2007 Share Posted June 12, 2007 Just send them all in one go, no need to sleep or anything like that. They don't take much time to send. Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273306 Share on other sites More sharing options...
smc Posted June 12, 2007 Share Posted June 12, 2007 Well hypothetically speaking you could add an integer and an if statement saying if( $i == 100 || $i == 200 ){ sleep( 10 ); } Then it would sleep on whatever numbers you specified, but I'm not sure why you would want to do that. Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273307 Share on other sites More sharing options...
dhimok Posted June 12, 2007 Author Share Posted June 12, 2007 Is it possible to reload the page after 100 emails and start over at next set, still running the script? Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273318 Share on other sites More sharing options...
smc Posted June 12, 2007 Share Posted June 12, 2007 Everytime you refresh the page it will re-parse so unless you have something like a DB table to confirm which ones sent and which ones didn't you won't be able to. You *may* be able to store them all as one huge array in a session variable but that would be pretty inefficent. Maybe if you explained why exactly you want to take a break between e-mailing? Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273341 Share on other sites More sharing options...
dhimok Posted June 12, 2007 Author Share Posted June 12, 2007 In case of 1 million subscribers (not likely) and each of them will receive an email, and maybe the script with timeout before reaching the last one, or should I not be concerned about this. Not quite sure Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273352 Share on other sites More sharing options...
chigley Posted June 12, 2007 Share Posted June 12, 2007 Use ini_set() to set the maximum execution time, and just loop through all of them. It won't timeout as long as it doesn't hit a neverending loop. Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273358 Share on other sites More sharing options...
smc Posted June 12, 2007 Share Posted June 12, 2007 Use ini_set() to set the maximum execution time, and just loop through all of them. It won't timeout as long as it doesn't hit a neverending loop. Exactly, like I said above. My server has a maximum execution time of 30 seconds, however I have a script that runs for a little of an hour. Execution time only exists when it hits a neverending loop and thus hangs executing that one function for the preset length of time. To e-mail 1 million subscribers will take quite a while, but the PHP script won't timeout as long as it is pogrammed correctly without any never-ending loops. Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273370 Share on other sites More sharing options...
iceblox Posted June 12, 2007 Share Posted June 12, 2007 For future information how would chigleys script work with html as the email. As i added some html but in just showed the html code in the browser... Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273380 Share on other sites More sharing options...
dhimok Posted June 12, 2007 Author Share Posted June 12, 2007 Ok, thanks, I guess there are no worries then Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273386 Share on other sites More sharing options...
The Little Guy Posted June 12, 2007 Share Posted June 12, 2007 So it wont time out: http://us.php.net/set_time_limit Quote Link to comment https://forums.phpfreaks.com/topic/55290-sending-newsletter-in-cycles/#findComment-273390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.