corkg Posted March 7, 2008 Share Posted March 7, 2008 Hi I am having trouble sending out a digest for a forum it should send out 50 mails but only manages 30. And comes up with this in the log: "aborted: (first read) idle timeout (30 sec)" My code is as below any idea on how to extend the timeout. $res = mail($selectedig->email,$subject,$message,"From:$strFrom\r\nReply-to: $strFrom\r\nContent-type: text/html; charset=us-ascii", "[email protected]"); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/ Share on other sites More sharing options...
micah1701 Posted March 7, 2008 Share Posted March 7, 2008 you might be able to tweak your max_execution_time in your php configuration .ini file but that can only help so much. What if eventually you have 100 or 500 e-mails. I've had this problem before and found the best solution is to fork the script. There was a tutorial here at phpfreaks.com a while back but I can't seem to find it. basically, you use an exec() command to execute a child file which includes all your code to send out the e-mails from the server. The parent script doesn't have to sit around an wait for it to finish and therefore doesn't time out. edit:here is google's cache of that tutorial Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-486215 Share on other sites More sharing options...
corkg Posted March 7, 2008 Author Share Posted March 7, 2008 Thanks I will try this tommorow when i have more time. Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-486406 Share on other sites More sharing options...
corkg Posted March 7, 2008 Author Share Posted March 7, 2008 Getting this: Warning: exec() has been disabled for security reasons Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-486426 Share on other sites More sharing options...
BlueSkyIS Posted March 7, 2008 Share Posted March 7, 2008 that means that exec() has been disabled for security reasons. it's probably turned off in php.ini, or PHP is running in safe mode. if you don't have access to php.ini and/or the ability to turn off safe mode, you'll need to talk to your system admin to see if they'll change the configuration for you. If you can live without forking, try using ini_set to set the max_execution_time to something higher than 30 seconds. ini_set('max_execution_time', '60'); Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-486482 Share on other sites More sharing options...
corkg Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-486889 Share on other sites More sharing options...
corkg Posted March 8, 2008 Author Share Posted March 8, 2008 Where do i put this "ini_set('max_execution_time', '60');" I put it in the php but did not work. I can't access the .ini or turn on exec() because i am on a public server. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-487191 Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 all ini_set() should be done at the top of the script before anything else. Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-487195 Share on other sites More sharing options...
laffin Posted March 8, 2008 Share Posted March 8, 2008 U shud look at using BCC in yer emails instead of emailing everyone individually. initializer code (before yer loop) $to = ""; $nmax = 100; // Max recipients per message $nthis = 0; $ntotal = 0; $cbcc=array(); $bbcc=array(); List builder (in yer loop) $cbcc[]=$selectedig->email; ++$nthis; ++$ntotal; if ($nthis == $nmax) { $bbcc[]=$cbcc; $cbcc=array(); $nthis=0; } now $bbcc contains batches of emails to send after the loop we mail everything $i=0; $errors=array(); foreach($bbcc as $bccl) { $i++; $bcc = implode(',',$bccl); $res = mail("Multiple recipients <$strFrom>",$subject,$message,"From:$strFrom\r\nReply-to: $strFrom\r\nBcc: $bcc\r\nContent-type: text/html; charset=us-ascii", "[email protected]"); if($res==false) { $errors[$i]=count($bccl); } $hm=array_sum($errors); echo number_format($ntotal-$hm). " of $ntotal emals sent."; now ya have 100 emails going out per mail usage, I dun think ya shud encounter the problem again well until ya hit (50*100=5000) distribution list Quote Link to comment https://forums.phpfreaks.com/topic/94919-mail-script-timeout/#findComment-487259 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.