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

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)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 22 - 6 = ?

 
 [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 https://pear.php.net/bugs/bug.php?id=17865. 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 <hawl@tpg.com.au>"; $to = "H <hawl@tpg.com.au>"; $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' => 'mail.tpg.com.au', '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 mail.tpg.com.au ESMTP (mail14) Sendmail ready. DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mail14.tpgi.com.au Hello sysadmin- 03.tpgi.com.au [203.29.157.33], 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:<hawl@tpg.com.au> DEBUG: Recv: 250 2.1.0 <hawl@tpg.com.au>... Sender ok DEBUG: Send: RCPT TO:<hawl@tpg.com.au> DEBUG: Recv: 250 2.1.5 <hawl@tpg.com.au>... Recipient ok DEBUG: Send: DATA DEBUG: Recv: 354 Enter mail, end with "." on a line by itself DEBUG: Send: From: H <hawl@tpg.com.au> To: H <hawl@tpg.com.au> 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)

Comments

 [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 pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net 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.