Page 1 of 1

using AntiFlood and Throttle together

Posted: Wed Jan 21, 2009 2:56 pm
by audrey
I've been using the AntiFlood plugin for a little while now with success but have just encoutered an error:

-- snip --
[Wed Jan 21 14:08:41 2009] [error] [client 209.90.147.154] PHP Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'There was a problem reading line 1 of an SMTP response. The response so far was:<br />[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0) '

in /usr/share/pear/Swift-3.3.2-php5/lib/Swift/Connection/SMTP.php:250
Stack trace:
#0 /usr/share/pear/Swift-3.3.2-php5/lib/Swift.php(306): Swift_Connection_SMTP->read()
#1 /usr/share/pear/Swift-3.3.2-php5/lib/Swift.php(231): Swift->command('QUIT')
#2 /usr/share/pear/Swift-3.3.2-php5/lib/Swift/BatchMailer.php(150): Swift->disconnect()
#3 /usr/share/pear/Swift-3.3.2-php5/lib/Swift/BatchMailer.php(221): Swift_BatchMailer->forceRestartSwift()
#4 /usr/share/pear/Swift-3.3.2-php5/lib/Swift.php(487): Swift_BatchMailer->send(Object(Swift_Message), Object(Swift_RecipientList), Object(Swift_Address))
#5 /var/www/vhosts/DOMAIN/htdocs/administer/mail_members.php(112): Swift->batchSend(Object(Swift_Message), Object(Swift_RecipientList), Object( in /usr/share/pear/Swift-3.3.2-php5/lib/Swift/Connection/SMTP.php
on line 250, referer: http://DOMAIN/administer/mail_members.php
-- snip --

(the exception wasn't caught because I was trying to catch Swift_Connection_Exception instead of Swift_ConnectionException--oops)

My code is, basically:

Code: Select all

function sendIt($recipients, $subject, $message)
{
    $swift = new Swift(new Swift_Connection_SMTP('localhost'), 'DOMAIN');
    
    /* 100 mails per batch with a 60 second pause between batches
     */
    $swift->attachPlugin(new Swift_Plugin_AntiFlood(100, 60), 'anti-flood');
 
    set_time_limit(0); ignore_user_abort();
 
    flush();
    
    try
    {
        $html_content = $message;
        $plain_content = stripMarkup($message);
 
        $message = new Swift_Message($subject);
        
        // create the message and set a few things ...
        
        $message->attach(new Swift_Message_Part($plain_content));
        $message->attach(new Swift_Message_Part($html_content, 'text/html'));
 
        $num_sent = $swift->batchSend($message, $recipients, new Swift_Address(EMAIL_ADMIN, '...'));
        
        $swift->disconnect();
        return TRUE;
    }
    catch (Swift_ConnectionException $e)
    {
        echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
        exit;
    }
    catch (Swift_Message_MimeException $e)
    {
        echo 'There was an unexpected problem building the email: ' . $e->getMessage();
        exit;
    }
}
I found a discussion about this same error at this link:

viewtopic.php?f=52&t=75848

It does seem to me that the first thing to try would be to reduce the number of messages per batch. But, I'm also interested in using Throttle as well. But, before I simply reduce the number of messages sent at a time, I'd like to understand a bit better how I can use the Throttle plugin with AntiFlood. It's not clear to me how I would use these 2 plugins together, nor if I should do so. For example, how does Throttle's emailsPerMinute interact with AntiFlood's timeout?

Can someone please clarify this?

Re: using AntiFlood and Throttle together

Posted: Wed Jan 21, 2009 7:03 pm
by Chris Corbyn
The throttler and the anti-flood plugin are compatible. Throttler reads the system time, so if AntiFlood has been paused for 5 seconds, Throttler will take that pause into account.