FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=17888&edit=1

ID: 17888
Updated by: alec@alec.pl
Reported By: haw dot loeung at tpg dot com dot au
Summary: Patch to reduce peak memory usage when using the smtp
driver
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Mail
Operating System: Linux
Package Version: 1.2.0
PHP Version: 5.3.3
-Assigned To:
+Assigned To: alec
Roadmap Versions:
New Comment:

-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: alec
Net_SMTP 1.4.3 fixes this issue.


Previous Comments:
------------------------------------------------------------------------

[2010-09-23 03:42:44] hloeung

Added #patch
bug:17888;patch:Mail_smtp.php-reduce-peak-mem-usage.patc;revision:1285213364;.

------------------------------------------------------------------------

[2010-09-23 03:41:26] hloeung

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]

------------------------------------------------------------------------

Search Discussions

  • Haw Loeung at Jan 8, 2011 at 9:32 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=17888&edit=1

    ID: 17888
    Updated by: haw.loeung@tpg.com.au
    Reported By: haw dot loeung at tpg dot com dot au
    Summary: Patch to reduce peak memory usage when using the smtp
    driver
    -Status: Closed
    +Status: Open
    Type: Feature/Change Request
    Package: Mail
    Operating System: Linux
    Package Version: 1.2.0
    PHP Version: 5.3.3
    Assigned To: alec
    Roadmap Versions:
    New Comment:

    -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.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-01-08 13:10:16] alec

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: alec
    Net_SMTP 1.4.3 fixes this issue.

    ------------------------------------------------------------------------

    [2010-09-23 03:42:44] hloeung

    Added #patch
    bug:17888;patch:Mail_smtp.php-reduce-peak-mem-usage.patc;revision:1285213364;.

    ------------------------------------------------------------------------

    [2010-09-23 03:41:26] hloeung

    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]

    ------------------------------------------------------------------------
  • Alec at Jan 10, 2011 at 8:22 am
    Edit report at http://pear.php.net/bugs/bug.php?id=17888&edit=1

    ID: 17888
    Updated by: alec@alec.pl
    Reported By: haw dot loeung at tpg dot com dot au
    Summary: Patch to reduce peak memory usage when using the smtp
    driver
    Status: Assigned
    Type: Feature/Change Request
    Package: Mail
    Operating System: Linux
    Package Version: 1.2.0
    PHP Version: 5.3.3
    Assigned To: alec
    Roadmap Versions:
    New Comment:

    I was thinking about parsing message body in chunks implemented in
    Net_SMTP 1.4.3, but you're right about the string catenation.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-01-08 22:34:16] hloeung

    -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-08 13:10:16] alec

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: alec
    Net_SMTP 1.4.3 fixes this issue.

    ------------------------------------------------------------------------

    [2010-09-23 03:42:44] hloeung

    Added #patch
    bug:17888;patch:Mail_smtp.php-reduce-peak-mem-usage.patc;revision:1285213364;.

    ------------------------------------------------------------------------

    [2010-09-23 03:41:26] hloeung

    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]

    ------------------------------------------------------------------------
  • Alec at Jan 14, 2011 at 6:53 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=17888&edit=1

    ID: 17888
    Updated by: alec@alec.pl
    Reported By: haw dot loeung at tpg dot com dot au
    Summary: Patch to reduce peak memory usage when using the smtp
    driver
    -Status: Assigned
    +Status: Closed
    Type: Feature/Change Request
    Package: Mail
    Operating System: Linux
    Package Version: 1.2.0
    PHP Version: 5.3.3
    Assigned To: alec
    -Roadmap Versions:
    +Roadmap Versions: 1.2.1
    New Comment:

    -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.




    Previous Comments:
    ------------------------------------------------------------------------

    [2011-01-10 09:23:42] alec

    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-08 22:34:16] hloeung

    -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-08 13:10:16] alec

    -Status: Open
    +Status: Closed
    -Assigned To:
    +Assigned To: alec
    Net_SMTP 1.4.3 fixes this issue.

    ------------------------------------------------------------------------

    [2010-09-23 03:42:44] hloeung

    Added #patch
    bug:17888;patch:Mail_smtp.php-reduce-peak-mem-usage.patc;revision:1285213364;.

    ------------------------------------------------------------------------

    [2010-09-23 03:41:26] hloeung

    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]

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 8, '11 at 12:08p
activeJan 14, '11 at 6:53p
posts4
users2
websitepear.php.net

2 users in discussion

Alec: 3 posts Haw Loeung: 1 post

People

Translate

site design / logo © 2021 Grokbase