homepage Welcome to WebmasterWorld Guest from 54.211.230.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
phpmailer slowness
Is there a way to speed up smtp connection
oddjob5

5+ Year Member



 
Msg#: 4625357 posted 10:13 am on Nov 22, 2013 (gmt 0)

Hi all,

I help run a website with a lot of members. Throughout the day i have to email members notifications with unique content in each email. I have set up a cron job to check the database for new email notifications that need to be sent every 2 hours. The script is now taking over 2 hours to complete sending and i am looking to make it more efficient. The code below is what i use. When i time the script the delay seems to be from connecting to sendmail which is on the same server. Can anyone give me an idea on how to speed this up? Also what is the best way of finding dead email address's where domains have expired or unknown user?

while($list_array=mysql_fetch_array($info_query))
{
$mail=new PHPMailer();
$mail->From = "noreply@example.com";
$mail->FromName = "No Reply";
$mail->Host = "localhost";
$mail->Mailer = "smtp";
$mail->isSMTP();
$mail->SMTPKeepAlive = true;

$mail->IsHTML(FALSE);
$mail->Body = $list_array[text_body];

$mail->AddAddress($list_array[toemail], $list_array[toname]);
$mail->Subject = "$list_array[subject]";

if($mail->Send())
{
// insert into table notification sent
}

$mail->ClearAddresses();
$mail->ClearAttachments();

$mail->SmtpClose();
}

 

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 4625357 posted 5:46 pm on Nov 25, 2013 (gmt 0)

How many emails are you able to send in the 2 hours?

You seem to be closing the SMTP socket for each email. I imagine this will need to be kept open if sending multiple emails.

swa66

WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4625357 posted 6:44 pm on Nov 25, 2013 (gmt 0)

Also what is the best way of finding dead email address's where domains have expired or unknown user?

You must process "bounces": returned mail deemed undeliverable and act on it by suspending those that will continue to fail for the forseaable future. Take care not to process it based on out-of-office replies (it's tricky!)

There are services out there that can handle huge amounts of emails being sent out (I prefer to use them over having my servers flagged as "spammer"). They do handle processing of bounces for you.

bhukkel



 
Msg#: 4625357 posted 7:20 pm on Nov 25, 2013 (gmt 0)

Perhaps you can look at your sendmail configuration and see if there are any DNS blacklists configured like spamhaus. This will slow down the connection.

Also an option to run multithreaded within PHP or run several cronjobs.

oddjob5

5+ Year Member



 
Msg#: 4625357 posted 9:38 am on Nov 26, 2013 (gmt 0)

Thanks for the replies. The script is managing to send out 7500 emails in 2 hours. The reason i close the smtp connection after every email is to avoid looking like the server is spamming. It does speed up if i leave the connection open for 15 emails and then reconnect. The slowness does seem to come from the connecting to sendmail.
I will look into running multithreaded or several cronjobs.

swa66

WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4625357 posted 9:51 am on Nov 26, 2013 (gmt 0)

If you're connecting to your own SMTP server: other servers will not know either way if you dropped the connection or not. I'd suggest to keep it open as long as your script runs.
It might help to make sure DNS on your server (as client) is configured so that it can do a reverse lookup of 127.0.0.1 (and the same for IPv6). sendmail does that and if it needs to wait for a time-out on DNS it'll slow things down to a crawl.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved