distractedGuy
distractedGuy

Reputation: 41

phpMailer doesn't timeout after given time

$mailer = new SMTP;    
$mailer->Timeout = 5;    
$mailer->connect($host, $port)    

This should cancel the connect() after 5 seconds, but the timeout takes much longer and don't cancel after 5 seconds.

How can I force my script to stop trying connect to the SMTP after 5 seconds?

I'm looking forward for your answers.

Best regards,

distractedGuy

Upvotes: 4

Views: 1416

Answers (1)

Synchro
Synchro

Reputation: 37770

There are two timeouts in PHPMailer's SMTP class - Timeout and Timelimit.

Timeout applies when making the initial TCP connection. Timelimit is the duration allowed for each SMTP command's response. Both default to 5 minutes (in accordance with the RFCs) - so it could be that you are connecting quickly, but then the server is very slow to respond to commands. You should try setting the Timelimit to a lower value like this:

$mail->getSMTPInstance()->Timelimit = 5;

All of this should serve to remind you that SMTP is not intended to be an interactive, immediate protocol, so you should only be using SMTP to a nearby server that can queue your request properly.

Upvotes: 7

Related Questions