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

Request #17888 Patch to reduce peak memory usage when using the smtp driver
Submitted: 2010-09-23 02:41 UTC Modified: 2011-01-14 19:55 UTC
From: hloeung Assigned: alec
Status: Closed Package: Mail (version 1.2.0)
PHP Version: 5.3.3 OS: Linux
Roadmaps: 1.2.1    
Subscription  


 [2010-09-23 02:41 UTC] hloeung (Haw Loeung)
Description: ------------ The Net_SMTP package now supports providing headers as an optional second parameter to data(). This reduces the peak memory usage, especially for large messages. Test script: --------------- <?php include_once 'Mail.php'; $fh = fopen('20mbody.txt', 'r'); $body = fread($fh, filesize('20mbody.txt')); fclose($fh); $headers = array ('From' => 'hawl@tpg.com.au', 'To' => 'hawl@tpg.com.au', 'Subject' => 'Testing'); $smtp = Mail::factory('smtp', array ('host' => 'mail.tpg.com.au','debug' => '0')); echo 'file=' . substr(__FILE__, strrpos(__FILE__, '/') + 1) . '; line=' . __LINE__ . '; mem_used=' . memory_get_usage(0) . ' [' . memory_get_usage(1) . ']; peak_mem=' . memory_get_peak_usage(0) . ' [' . memory_get_peak_usage(1) . "]\n"; $smtp->send('hawl@tpg.com.au', $headers, $body); echo 'file=' . substr(__FILE__, strrpos(__FILE__, '/') + 1) . '; line=' . __LINE__ . '; mem_used=' . memory_get_usage(0) . ' [' . memory_get_usage(1) . ']; peak_mem=' . memory_get_peak_usage(0) . ' [' . memory_get_peak_usage(1) . "]\n"; ?> Expected result: ---------------- file=test-mail.php; line=13; mem_used=23399400 [23592960]; peak_mem=23416944 [23592960] file=test-mail.php; line=15; mem_used=23975576 [24379392]; peak_mem=27079840 [27525120] Actual result: -------------- file=test-mail.php; line=13; mem_used=23399456 [23592960]; peak_mem=23416832 [23592960] file=test-mail.php; line=15; mem_used=23975704 [24379392]; peak_mem=49502792 [50069504]

Comments

 [2010-09-23 02:42 UTC] hloeung (Haw Loeung)
 [2011-01-08 13:10 UTC] alec (Aleksander Machniak)
-Status: Open +Status: Closed -Assigned To: +Assigned To: alec
Net_SMTP 1.4.3 fixes this issue.
 [2011-01-08 22:34 UTC] hloeung (Haw Loeung)
-Status: Closed +Status: Open
alec, Net_SMTP 1.4.3 doesn't fix this issue. Newer versions of Net_SMTP have added support for providing the headers and the data separately which Mail (Mail/smtp.php) currently doesn't make use of. Please see the patch provided. Currently: $res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body); Proposed change: $res = $this->_smtp->data($body, $textHeaders); In the current state, the headers and body needs to be joined together with a line separating the two. If the e-mail was something like 20MB then the peak memory usage increases by another 20MB. The proposed change takes away the need for joining the header and body and just passes them to Net_SMTP's data() method separately.
 [2011-01-10 09:23 UTC] alec (Aleksander Machniak)
I was thinking about parsing message body in chunks implemented in Net_SMTP 1.4.3, but you're right about the string catenation.
 [2011-01-14 19:55 UTC] alec (Aleksander Machniak)
-Status: Assigned +Status: Closed -Roadmap Versions: +Roadmap Versions: 1.2.1
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.