Page 1 of 1

It takes long to sent the mail out

Posted: Thu Mar 20, 2008 7:15 pm
by Stitch
Hello,

I'm verry impressed about the function swift has! I'm trying to implementate it into an newslettersystem, but sending the mails out is verry slow. It does send one mail per second! I have a couple of thousands recipients, so one second per email is a little too much.

But I am not sure or it is swifts fault, can it be that my mailserver only accepts one email per second? What is the avarage amount of emails that is possible to send with swift per second/minute?

Thanks,
Peter

Re: It takes long to sent the mail out

Posted: Thu Mar 20, 2008 7:26 pm
by Stitch
I tried another server: It takes one second to send 10 mails :P

So: It is an server problem...

Re: It takes long to sent the mail out

Posted: Fri Mar 21, 2008 1:59 am
by Josh1billion
Make sure you're using the batchSend() function when sending e-mails to a large amount of people at once.

Re: It takes long to sent the mail out

Posted: Fri Mar 21, 2008 2:04 am
by xdecock
Also, try to benchmark your "application code" by using an empty send() function.

This would show you how "quick" can your application go and so you should be able to see if the problem is on your MySQL queries (the most common problem in performances issues)

Re: It takes long to sent the mail out

Posted: Fri Mar 21, 2008 8:51 am
by Stitch
Josh: I have tried the normal send and the batchSend function, it doesn't matter it takes the same time.

xdecock: How do you mean exactly "an empty send() function"? I've tried

Code: Select all

$smtp = new Swift_Connection_SMTP('localhost');
$smtp->setUsername('username');
$smtp->setPassword('password');
 
$swift = new Swift($smtp);
 $swift->send();
$swift->disconnect();
 
But then I get an catchable fatal error:

Code: Select all

Catchable fatal error: Argument 1 passed to Swift::send() must be an instance of Swift_Message, none given, called in E:\vhosts\domain.tld\httpdocs\mailing\emptysend.php on line 21 and defined in E:\vhosts\domain.tld\httpdocs\mailing\lib\Swift.php on line 329
This is my test script:

Code: Select all

<?PHP
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/Decorator.php";
 
//Array with the mail addresses
$array[0] = "mail1@domain.tld";
$array[1] = "mail2@domain.tld";
$array[2] = "mail3@domain.tld";
 
//Instantiate Swift as usual
$smtp = new Swift_Connection_SMTP('localhost');
$smtp->setUsername('username');
$smtp->setPassword('password');
 
$swift = new Swift($smtp);
 
//Create the message, using some unique variables to search for
$message =& new Swift_Message("Hey {mail}.", "This is a message for {mail}!");
 
$recipients =& new Swift_RecipientList();
foreach($array as $value)
{
$replacements = array(
    $value => array("{mail}" => $value)
    );
 
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
$recipients->addTo($value);
}
 
//Send messages
$swift->batchSend($message, $recipients, new Swift_Address("email@domain.tld", "Peter"));
 
$swift->disconnect();
?>
I've done some performance tests, the batchSend function takes one second per email address.
I've asked my webhost the limit of sending emails per second, they told me that the limit is 32 mails/sec inbound and 16 mails/second outbound. This shouldn't be the problem, but how come on my other webhost the same script is well very fast? Could be the reason that this webhost is running windows and IIS and my secondary webhost an linux distrubution with appache running?

Re: It takes long to sent the mail out

Posted: Fri Mar 21, 2008 10:12 am
by Chris Corbyn
Stitch wrote:Josh: I have tried the normal send and the batchSend function, it doesn't matter it takes the same time.
Thank you! :) Finally someone realises they do the same thing! :D

batchSend() is just a big foreach() around send(). The optimization happens at a much lower level than inside the batch send function (i.e. within the storage layer of the mime components).

In other words, batchSend() vs. send() is the same speed (roughly speaking). The only difference with batchSend() is that it tries it best to handle errors on your behalf.