A
A
Alexander Avtomonov2016-07-07 16:02:46
PHP
Alexander Avtomonov, 2016-07-07 16:02:46

Why does PHPMailer require more than 1Gb of memory?

I'm trying to send emails via PHPMailer (PHP7 runs php-fpm under FreeBSD), code:

function mailSend ($addresses, $subject, $message)
{
    try {
        $mail = new PHPMailer;
        $mail->SMTPDebug = 3;
        $mail->setLanguage('ru', __DIR__ . '/PHPMailer/language/phpmailer.lang-ru.php');
        $mail->CharSet = MAIL_CHARSET;
        $mail->isSMTP();
        $mail->Host = MAIL_HOST;
        $mail->SMTPAuth = true;
        $mail->Username = MAIL_USERNAME;
        $mail->Password = MAIL_PASSWORD;
        $mail->SMTPSecure = 'ssl';
        $mail->Port = MAIL_PORT;

        $mail->From = MAIL_FROM;
        $mail->FromName = MAIL_FROM_NAME;
        $mail->addAddress($addresses);
        $mail->addReplyTo(MAIL_REPLYTO_ADDRESS, MAIL_REPLYTO_NAME);

        $mail->WordWrap = 50;
        //$mail->addAttachment('/var/tmp/file.tar.gz');
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
        $mail->isHTML(true);

        $mail->Subject = $subject;
        $mail->Body = $message;

        if (!$mail->send()) {
            echo 'false';
        } else {
            echo 'true';
        }
    }
    catch (Exception $e)
    {
        echo $e->getMessage();
    }
}

mailSend('[email protected]', 'test', 'test');

The script gives an error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1113159516 bytes) in /usr/local/www/avtomon.com/classes/PHPMailer/class.smtp.php on line 578.
I understand that the library large, but requiring more GB of memory is too much. What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
Uber Noob, 2016-07-08
@ubernoob

I work with it under php5.6 on a server with 512 RAM, everything is fine. I think it's in php-fpm or in php7, put xhprof, see which part is eating up all the memory

A
Alexander Avtomonov, 2016-07-08
@avtomon

If anyone needs it...
Solved the problem for now by commenting out this:

$sock_status = stream_get_meta_data($this->smtp_conn);
            if ($sock_status['eof']) {
                // The socket is valid but we are not connected
                $this->edebug(
                    'SMTP NOTICE: EOF caught while checking if connected',
                    self::DEBUG_CLIENT
                );
                $this->close();
                return false;
            }

in the connected method of the SMTP class, and this:
$info = stream_get_meta_data($this->smtp_conn);
            if ($info['timed_out']) {
                $this->edebug(
                    'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
                    self::DEBUG_LOWLEVEL
                );
                break;
            }

in the get_lines method of the same class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question