Jump to content

Mail Script Timeout


corkg

Recommended Posts

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", "-fnoreply@forum.org.uk");

 

Thanks

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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", "-fnoreply@forum.org.uk");
   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 :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.