Zend Framework

Out of memory on large sends

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Mail
  • Labels:
    None
  • Fix Version Priority:
    Should Have

Description

When sending large amounts of email using the Zend_Mail_Transport_Protocol classes it causes an out of memory problem. This is because each time the protected send method is called it attaches the request to the end of the log. In cases when a lot of emails are being sent this grows eventually causing the memory limit error.

I'm not sure this is the correct solution but I fixed it by resetting the log every time the send method is called:

class Yourlibrary_Mail_Transport_Smtp extends Zend_Mail_Transport_Smtp
{
    /**
     * Send a mail using this transport
     *
     * @param  Zend_Mail $mail
     * @access public
     * @return void
     * @throws Zend_Mail_Transport_Exception if mail is empty
     */
    public function send(Zend_Mail $mail)
    {
        $connection = $this->getConnection();
        if ($connection instanceof Zend_Mail_Protocol_Smtp) {
            $connection->resetLog();
        }
        return parent::send($mail);
    }
}

Activity

Hide
Fabio Napoleoni added a comment -

In my case the patch work, I send a small list of about 800 members and without this class my script crashes unless I raise memory limit up to 256M or even 512M.

But with this class the problem is gone.

Show
Fabio Napoleoni added a comment - In my case the patch work, I send a small list of about 800 members and without this class my script crashes unless I raise memory limit up to 256M or even 512M. But with this class the problem is gone.
Hide
Satoru Yoshida added a comment -

I think notation would be helpful.
The notation in document should notice in case user send many mails.

So, I change this issue to Docs: Improvement.

Show
Satoru Yoshida added a comment - I think notation would be helpful. The notation in document should notice in case user send many mails. So, I change this issue to Docs: Improvement.
Hide
Satoru Yoshida added a comment -

I added limitation of log counts at SVN r19008 (trunk).

I will be happy if you would try new code
This improvement would be released at 1.10.0 or later.

Show
Satoru Yoshida added a comment - I added limitation of log counts at SVN r19008 (trunk). I will be happy if you would try new code This improvement would be released at 1.10.0 or later.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: