I just wrote a set of bulk-emailing classes for handling enormous amounts of emails and parsing their content according to passed params. If I test an email on 1000 random recipients and 1000 random senders from my database, up until the point the script hits the send() part (I commented it for now), I get performance of around 2 seconds, and 20 MB peak memory, which is great.
However, if I uncomment the send part, the sending takes 30 seconds. This is unacceptable, and I would like to speed it up somehow. It is obvious from testing that the delay is caused by none other than the $mail->send() call, as if it's waiting for it to return something before continuing the loop and sending the next email.
What I'm wondering is: how do I speed up the send() call? What can I do to make it faster? I tried using two sending methods:
Please note that queueing is definitely an option, and I have built it into my classes. All it takes is activating a cron and it works like a charm. But I'm wondering about the actual sending and how to speed that up. So, the actual send() call.
I'd save the mails in a directory and send them using a shell script (cron/daemon/...):
Zend_Mail::setDefaultTransport(
new Zend_Mail_Transport_File(
array(
'path' => __DIR__,
'callback' => function() {
do {
$file = 'email-' . date('Y-m-d_H-i-s') . '_' . mt_rand() . '.eml';
} while (file_exists($file));
return $file;
},
)
)
);
You will need to speed up the MTA on the server. I recommend Postfix and that you really read up on each setting so you know how to fine-tune it. For a commercial solution I've heard PowerMTA is a good choice but I've never tried it myself.
There's only so much performance you can squeeze out of one machine, but a regular dedicated server should be able to deliver a rather impressive amount of mail once you've configured it correctly. The biggest performance bottleneck is usually the disk drives where the mail queue is stored, so consider using SAS (10k or even 15k RPM) or SSD drives.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With