Avoid PHP timeout when sending newsletter

Posted by Lars on Stack Overflow See other posts from Stack Overflow or by Lars
Published on 2009-08-17T17:33:35Z Indexed on 2010/04/30 5:17 UTC
Read the original article Hit count: 547

Filed under:
|
|

Hi,

I have recently implemented the Swiftmailer library, but the first time I used it, I got a php timeout error even though it only had to send out mails to around 300 people.. (I should mention that using the set_time_limit(0); workaround is not an option due to restrictions on the server)

The way I use it is like this:

 $transport = Swift_SmtpTransport::newInstance('smtp.mydomain.com',25);
 $mailer = Swift_Mailer::newInstance($transport);
 $message = Swift_Message::newInstance();
 $message->setSubject($_POST['subj']);
 $message->setFrom(array('email' => 'Mysite'));
 $message->setTo($recipients);
 $message->setBody(strip_tags($messagebody));
 $message->addPart($messagebody, 'text/html');
 $numSent = $mailer->batchSend($message);
 printf("Sent %d messages\n", $numSent);

where $recipients is a commaseparated array of emails (built with explode() from a mySQL query)..

I have no idea which part of the above code that generates the script-timeout, and since I use it for a newsletter function, it is rather difficult for me to test or debug it, so I would be really thankful for anyone coming up with a (near) bulletproof solution to this problem :)

Thanks in advance !

Lars

© Stack Overflow or respective owner

Related posts about php

Related posts about timeout