Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.0

Request #18197 Patch to add timeout to _parseResponse()
Submitted: 2011-01-17 13:10 UTC
From: hloeung Assigned: jon
Status: Closed Package: Net_SMTP (version 1.4.4)
PHP Version: 5.3.5 OS: Linux
Roadmaps: (Not assigned)    

 [2011-01-17 13:10 UTC] hloeung (Haw Loeung)
Description: ------------ Under certain circumstances, __parseResponse() will hang waiting for a reply code. In my case see bug report This patch adds a timeout to _parseResponse(). I can't find the minimum timeout value from RFC2821/RFC5321 so decided to go with a value of 1 minute. Test script: --------------- <?php include_once "Mail.php"; $from = "H <>"; $to = "H <>"; $subject = "Hi!"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $fh = fopen('20mbody.txt', 'r'); $body = fread($fh, filesize('20mbody.txt'));; fclose($fh); $smtp = Mail::factory('smtp', array ('host' => '', 'debug' => '1')); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> Expected result: ---------------- The script should terminate instead of hanging at the DATA stage of an SMTP transaction waiting for a reply code. Actual result: -------------- $ time php test1.php DEBUG: Recv: 220 ESMTP (mail14) Sendmail ready. DEBUG: Send: EHLO localhost DEBUG: Recv: Hello sysadmin- [], pleased to meet you DEBUG: Recv: 250-ENHANCEDSTATUSCODES DEBUG: Recv: 250-PIPELINING DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250-SIZE 28521268 DEBUG: Recv: 250-DSN DEBUG: Recv: 250-AUTH LOGIN PLAIN DEBUG: Recv: 250-STARTTLS DEBUG: Recv: 250-DELIVERBY DEBUG: Recv: 250 HELP DEBUG: Send: MAIL FROM:<> DEBUG: Recv: 250 2.1.0 <>... Sender ok DEBUG: Send: RCPT TO:<> DEBUG: Recv: 250 2.1.5 <>... Recipient ok DEBUG: Send: DATA DEBUG: Recv: 354 Enter mail, end with "." on a line by itself DEBUG: Send: From: H <> To: H <> Subject: Hi! PHP Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 512001 bytes) in /usr/share/php/Net/SMTP.php on line 903 Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 512001 bytes) in /usr/share/php/Net/SMTP.php on line 903 DEBUG: Send: QUIT (hangs here waiting for a reply code)


 [2011-01-17 13:13 UTC] hloeung (Haw Loeung)
 [2011-01-17 13:22 UTC] hloeung (Haw Loeung)
-Summary: Add timeout to _parseResponse() +Summary: Patch to add timeout to _parseResponse()
 [2011-01-18 10:27 UTC] jon (Jon Parise)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: jon
You can already set the socket's timeout value via the Net_SMTP class' connect() method: function connect($timeout = null, $persistent = false) Did you miss that existing functionality, or does that not cover your use case?
 [2011-01-20 11:39 UTC] hloeung (Haw Loeung)
Setting the socket's timeout would work but it applies to all socket operations. Reading the SMTP reply code should use a smaller timeout value and should be enforced even if a timeout value is provided.
 [2011-02-07 09:05 UTC] jon (Jon Parise)
-Status: Feedback +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I took a different approach: a new constructor parameter is used to specific the general socket I/O timeout value. The existing $timeout parameter to the connect() method is only used for the initial connection attempt.