Welcome to WebmasterWorld Guest from 54.227.83.19

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

phpmailer slowness

Is there a way to speed up smtp connection

     

oddjob5

10:13 am on Nov 22, 2013 (gmt 0)

10+ Year Member



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

5:46 pm on Nov 25, 2013 (gmt 0)

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



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

6:44 pm on Nov 25, 2013 (gmt 0)

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



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

7:20 pm on Nov 25, 2013 (gmt 0)

5+ Year Member



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

9:38 am on Nov 26, 2013 (gmt 0)

10+ Year Member



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

9:51 am on Nov 26, 2013 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month