Page 1 of 1

Logging and memory usage

Posted: Wed May 14, 2008 10:06 am
by batfastad
Hi everyone

I'm in the process of converting our e-mail newsletter script over to SwiftMailer from PHPMailer, and I'm at the point where I need to start to consider what I'm going to do about logging.
We send 2-3 newsletters per day, to about 1500 recipients each. Currently we send using PHPMailer and nativemail, and the sending script is hosted on our ISPs webspace. I contacted them in advance and they approved this arrangement, we've not had any problems for a couple of years now.

I'm considering using SwiftMailer to send through SMTP using our ISPs relay, rather than with nativemail.
I've not decided whether to host the actual sending script on our ISPs webspace, or on our intranet Apache/PHP server. I will do testing to discover which is faster.
I'm planning on using the AntiFlood, BandwidthMonitor and Decorator plugins, and sending using the batchsend method. With

Code: Select all

ignore_user_abort(TRUE)
enabled so the script can run without getting interrupted.

Here's what I'd like to be able to record...
  • - Sent/failed totals
    - Which recipients failed
    - How long in total the sending/script took
    - Peak and average memory usage
    - Total SMTP bandwidth (BandwidthMonitor plugin)
Are these possible through Swift's logging capabilities?
I guess the memory analysis needs to use PHPs memory functions, and the timing again is something I can knock up with PHP's microtime
I'm then planning to send this log to the user via e-mail.

With ignore_user_abort enabled, is there a way I can be notified if the script terminates at any point, without reaching the end?

Thanks, B

Re: Logging and memory usage

Posted: Wed May 14, 2008 8:58 pm
by Chris Corbyn
I really wouldn't advise using ignore_user_abort(). It's a last-alternative solution but you should consider using cron and storing mail in a queue in the database if you need something which is going to take a very long time.

As far as I know, there's no way to determine the point when the request is ended and the process continues in the background.

Re: Logging and memory usage

Posted: Thu May 15, 2008 11:06 am
by batfastad
Ah right, ok

With PHPMailer the script currently takes about 2-5 minutes. And that's because it loops through each array element and sends the same message.
I'm assuming Swift will give me a speed boost there as it appears to be way more efficient!

I'll run some tests and see if I have any troubles with the script completing.

It also looks like I'll be running the script on our ISPs webspace, as our PHPMailer version currently is. And I reckon we'll be using the SendMail connection rather than SMTP. Should be faster to get through the mails.

I've managed to work out how to get a few of the stats I'm looking for, hope this helps some people out:

Code: Select all

$total_sent = $swift->batchSend($message, $recipients, new Swift_Address('newsletter@abcinc.com', $from_name));
$bandwidth_in = $bandwidth->getBytesIn();
$bandwidth_out = $bandwidth->getBytesOut();
 
$failed = $swift->getFailedRecipients();
$total_failed = count($failed);
// LOOP THROUGH FAILED RECIPIENTS
foreach ($failed as $value) {
    $failed_emails .= $value."\r\n";
}
$script_time = round( microtime(true) - $script_time_start, 4);
Thanks, B