it takes very long to send a few mails (15 secs - 3 emails)
Posted: Sat May 31, 2008 6:41 pm
hi,
everything seems to work perfect, however, it takes very long to send a few emails to the list of persons in my MySql database.
A test to send emails to only 3 different email addresses took 15 seconds and 1 of them even failed to pass. A small mailinglist of not even 100 members took almost one hour, where -again - one third failed delivery / acceptance.
I checked the documentation, tutorials and this forum, but unfortunately I am still stuck with this problem. I am new here, but eager to learn of course.
- how long should it normally take to send a small mailinglist?
- as I think that my above mentioned situation is not how it is supposed to work, I must overlook
something, but what?
to give an idea of the situation, here some more info:
- website runs on a Linux server (shared)
- Apache 2.0.61
- PHP 4.4.8
- MySql 4.1.22
a piece of (relevant) code:
I hope I explained clear enough - some advise here is much appreciated:
why is it running slow?
where to look first?
thank you.
Paul
everything seems to work perfect, however, it takes very long to send a few emails to the list of persons in my MySql database.
A test to send emails to only 3 different email addresses took 15 seconds and 1 of them even failed to pass. A small mailinglist of not even 100 members took almost one hour, where -again - one third failed delivery / acceptance.
I checked the documentation, tutorials and this forum, but unfortunately I am still stuck with this problem. I am new here, but eager to learn of course.
- how long should it normally take to send a small mailinglist?
- as I think that my above mentioned situation is not how it is supposed to work, I must overlook
something, but what?
to give an idea of the situation, here some more info:
- website runs on a Linux server (shared)
- Apache 2.0.61
- PHP 4.4.8
- MySql 4.1.22
a piece of (relevant) code:
Code: Select all
define("TEST_CONFIG_PATH", dirname(__FILE__));
define("DEFAULT_WRITABLE_PATH", TEST_CONFIG_PATH . "/tmp");
$WRITABLE_PATH = DEFAULT_WRITABLE_PATH;
require_once "./swift_mail/Swift.php";
require_once "./swift_mail/Swift/Connection/SMTP.php";
require_once "./swift_mail/Swift/Plugin/AntiFlood.php"; require_once "./swift_mail/Swift/Plugin/VerboseSending.php"; require_once "./swift_mail/Swift/Plugin/Throttler.php";
require_once "./swift_mail/Swift/Plugin/Decorator.php";
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("mail.xxxxxx.com"));
//use Disk Caching:
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath($WRITABLE_PATH); // /tmp-folder chmod 777
//-------------------------------------------------------------------------------------
$throttler =& new Swift_Plugin_Throttler();
$throttler->setBytesPerMinute(20000000);
$swift->attachPlugin($throttler, "throttler");
//-------------------------------------------------------------------------------------
$view =& new Swift_Plugin_VerboseSending_DefaultView();
$swift->attachPlugin(new Swift_Plugin_VerboseSending($view), "verbose");
//-------------------------------------------------------------------------------------
$swift->attachPlugin(new Swift_Plugin_AntiFlood(100, 10), "anti-flood");
//------------------------------------------------------------------------------------------------------
$message =& new Swift_Message($_POST[subject]);
$img1 = & new Swift_Message_Image(new Swift_File("./swift_files/banner.gif"));
$src1 = $message->attach($img1);
$content = nl2br(stripslashes($_POST['content']));
$contentplain = str_replace("<br />","\n",$content);
//Create the plain text message
$body_txt = "Dear {first_name},\n\n".
"$contentplain\n\n\n".
"Best regards,\n".
"etc...\n\n";
//Create the html text message
$body_html = "<br>".
"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">".
// ---------- BODY -------------
"Dear {first_name},<br><br>".
"$content<br><br><br>".
"Best regards,<br>".
"xxxxx<br>".
// ---------- BODY -------------
ETC.ETC.ETC.";
$message->attach(new Swift_Message_Part($body_txt));
$message->attach(new Swift_Message_Part($body_html, "text/html"));
class Replacements extends Swift_Plugin_Decorator_Replacements {
function getReplacementsFor($address) {
$query = "SELECT
first_name as '{first_name}', id as '{id}'
FROM members
WHERE email_address = '" . mysql_real_escape_string($address) . "'";
$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");
$count_emails = 0;
$recipients =& new Swift_RecipientList();
// selected clients ...
foreach($_POST[clients] AS $id => $mail){
$recipients->addTo($mail);
$count_emails = $count_emails+1;
}
if ($swift->batchSend($message, $recipients, new Swift_Address($from, $from_name))){
echo "<p class=\"txb\">message Sent!";
}else{
echo "<p class=\"txb\">message Failed ...";
}
echo 'Email sent to '.$count_emails.' members </p>';
$swift->disconnect();
I hope I explained clear enough - some advise here is much appreciated:
why is it running slow?
where to look first?
thank you.
Paul