SwiftMailer library running slow

I am trying to inject swiftmailer into this mail system. my client has about 300 thousand active emails that need to be sent on a regular basis. the system was initially configured for the sendmail and php mail () functions. Since then I have installed the latest version of the postfix.

Perhaps my expectations were too high, but I was impressed that this thing could put a lot of letters in the FAST queue, which is exactly what I need. all speed control and throttling are done on the postfix side, so the ability to queue in a queue as fast as my postfix settings can handle would be great.

while I could implement methods to insert a contact directly into the queue, I would rather limit the entry of email messages into the queue based on various parameters, such as global send speeds for the smtp server.

the code below is just basic for testing. it moves through 30 separate SMT mail accounts, each of which has its own speed properties. I am trying to get the maximum number of emails from db for cron, and then send everything using batchsend(), then go to the next smtp account, send max, etc.

technically it really works, however it is really slow. at a speed of 60 rpm per SMTP account, this takes about 15-20 seconds, each of which, obviously, will not work, and not at all what I expected.

Is there anything really obvious about why this will be so slow? smtp servers seem to be beautiful, without overload or anything like that. no postfix errors, nothing obvious.

after the emails are queued, I will let postfix work with magic. he enters the queue at a reasonable speed, which becomes difficult. I know that swiftmailer is a magical solution to all my problems, but I'm sure it should send faster than it is. any ideas or suggestions?

$query = "SELECT * FROM `smtp`";
    $result = mysql_query($query) or die(mysql_error());
    $num_rows1 = mysql_num_rows($result);
    while($row = mysql_fetch_array($result)){
        $smtp = $row['ip'];
        $login = $row['user'];
        $pass = $row['pass'];
        $smtp_domain = $row['domain'];   

    $querya = "SELECT * FROM `mailer_lists` ml JOIN `mailer_controller` mc ON ml.project_name = mc.project_name LIMIT ".$global_limit."";
    $resulta = mysql_query($querya) or die(mysql_error());
    $num_rows2 = mysql_num_rows($resulta);

    // quickly check if any mail returned query
    if ($num_rows2 < 1){
        mysql_close($connection);
        echo "Nothing to mail... \n";
        die();
        }

    while($rowa = mysql_fetch_array($resulta)){
        $email[] = $rowa['email'];
        $project_name = $rowa['project_name'];
        $from_name = $rowa['from_name'];
        $subject = $rowa['subject'];
        $body = $rowa['body'];
        $from = array($spun_from_email => $spun_from_name);
    }    

    require_once 'swift/swift_required.php';
        $transport = Swift_SmtpTransport::newInstance(''.$smtp.'', 25)
          ->setUsername($login)
          ->setPassword($pass)
          ;
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance()
          ->setSubject($subject)
          ->setFrom($from)
         // ->addPart('add part message', 'text/html')
         // ->attach(Swift_Attachment::fromPath(''))
          ->setTo($email)
          ->setBody($body)
        ;
        $mailout = $mailer->batchSend($message);
         // ->addPart('add part message', 'text/html')
         // ->attach(Swift_Attachment::fromPath(''))
          ;  


            $queryb = "DELETE FROM `mailer_lists` WHERE `project_name` = '".$project_name."' AND `email` = '".implode('\' OR `email` = \'',$email)."'";  
            $resultb = mysql_query($queryb) or die(mysql_error());
            $c++;
            echo "sent $num_rows1 emails to smtp $c \n";
        }
+5
source share
1 answer

, . , ... , . , , .

  • script

require_once 'swift/swift_required.php';

  • smtp . , . , ( ), to, from ..

  • smtp , while.

+1

All Articles