Hi,
I am using SwiftMailer for the first time on a new project and I am trying to determine the capabilities of my server. The project is running on a dedicated windows 2003 server with an IMail SMTP server. My application needs to send large batch emails on the order of 50,000. How can I determine the capabilities of my SMTP server? Right now I am not able to determine how many messages are being sent. Here is what I am currently doing:
1. Construct the subject and body of the message.
2. Attach the decorator and anti-flood plugins (currently set to 500 emails every 10 seconds)
3. Use a while loop to add recipients to the recipient list
4. Send the message using batchSend()
At the end of my script I store the number returned by batchSend() in a database. My problem is that the database is not getting written to. So either the script is timing out or ????? I set my resource limits in php.ini to:
max_execution_time = 1200;
max_input_time = 60;
;max_input_nesting_level = 64 ;
memory_limit = 512M ;
I know that some addresses are getting through, I just don't know how many. When the anti-flood plugin is used does this determine the execution time of the script? So if I'm sending 30,000 emails it will take roughly:
(10 s/ 500) * 30,000 = 600 seconds
If this is true I believe my max_execution_time is set high enough, but I don't know for sure. Any help would be greatly appreciated.
Joe
Server capabilities using batchSend()
Moderators: Chris Corbyn, General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Server capabilities using batchSend()
Post your code please. 30,000 emails in one go is pretty mad. Are you sure your AntiFlood settings are good enough for the server to accept that many? Swift will throw an exception (thus causing a fatal error if uncaught) if the SMTP server doesn't respond or gives a bad response. Have you got error reporting on full? Quite hard to know what the problem is without seeing code 
Re: Server capabilities using batchSend()
Here is my code minus the database connection stuff:
How can I find out how many messages the smtp server will accept in a certain amount of time? Is it just a trial and error thing? Also, what sort of things should I be doing as far as catching errors?
Thanks
Code: Select all
<?php
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/Decorator.php";
require_once "lib/Swift/Plugin/AntiFlood.php";
$swift = new Swift(new Swift_Connection_SMTP("localhost"));
$subject = "....";
$body = "....";
$message = new Swift_Message($subject, $body);
//Extend the replacements class
class Replacements extends Swift_Plugin_Decorator_Replacements {
function getReplacementsFor($address) {
$query = ".......";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
return mysql_fetch_assoc($result);
}
}
}
//Load the plugin with the extended replacements class
$swift->attachPlugin(new Swift_Plugin_Decorator(new Replacements()), "decorator");
//Reconnect after 500 emails, but wait for 10 seconds first
$swift->attachPlugin(new Swift_Plugin_AntiFlood(500, 10), "anti-flood");
//Create recipient objects
$recipients = new Swift_RecipientList();
$sql = "........";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$email = $row['email'];
$recipients->addTo($email);
}
$from = new Swift_Address("....");
//Send messages
$num_sent = $swift->batchSend($message, $recipients, $from);
$sql = 'UPDATE ... SET .... = ' . $num_sent . ' WHERE ... = ... LIMIT 1;';
$result = mysql_query($sql);
//Disconnect from swift
$swift->disconnect();
?>
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Server capabilities using batchSend()
I suspect 500 is too many in one go. 100 is the standard limit.
Are you using PHP4 or 5?
This is how you want to be catching errors (assuming you're using PHP5). There are examples in the wiki 
http://www.swiftmailer.org/wikidocs/v3/ ... exceptions
Are you using PHP4 or 5?
Code: Select all
try {
//codes which uses Swift here
} catch (Swift_ConnectionException $e) {
//handle error
}http://www.swiftmailer.org/wikidocs/v3/ ... exceptions
Re: Server capabilities using batchSend()
Thanks Chris!
You were right. After lowering anti-flood to 100 every 10 seconds and messing with the mail server settings a bit I was able to get it to send about 35,000 emails in around 1 hour and 38 minutes. Thanks!
Joe
You were right. After lowering anti-flood to 100 every 10 seconds and messing with the mail server settings a bit I was able to get it to send about 35,000 emails in around 1 hour and 38 minutes. Thanks!
Joe
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Server capabilities using batchSend()
Glad to hear it 