...

View Full Version : Timeout issues with Mailing List script when sending to a large amount of emails...



Errica
12-04-2008, 04:34 PM
Would you mind looking at these pieces of code and perhaps offer a suggestion or two to work around timeout issues when sending to a large amount of email addresses? The max_execution_time on my server is set to 30 (which I cannot change). This script has a couple built-in featured to supposedly work around these issues but the few tweaks I've made don't seem to help when sending to about a thousand email addresses or more.

Here's the config section:


// When sending emails, ListMailer will pause periodically to avoid time-outs.
// This is helpful is your email list contains a large amount of address.
// The default value of 100 should suffice under most scenarios.
$cfg['pauseinterval'] = 100;

// Number of seconds to pause.
$cfg['pausetime'] = 3;

and here is the supporting code (hopefully, I've posted enough?):


if (isset($_POST['emailsub'])) {
// fetch addresses and process
$succ = 0; $fail = 0;
if ($cc) {
// send CC email if needed
if (@mail($cfg['ccaddress'], $subj, $body, $headers)) $succ++;
else $fail++;
}
$f = openfile($cfg['listfile']);
if ($startnum > 0) {
// skip to specified record and start there.
skiptoitem($f, $startnum);
}
if ($startpos > 0) {
// startpos is used for resuming. It will override any startnum value.
fseek($f, $startpos);
}
if ($cfg['savemail'] && !$_POST['resume']) {
// save this email only if it's not a resume and it is configured for.
if (($mfile = savemail($from, $subj, $body, $startid, $ashtml)) === false) $err = 'Could not save email. Check directory exists and permissions are set correctly.';
}
if (!isset($err)) {
// create temp file for resume data
if ($cfg['enableresume'] && $cfg['savemail']) {
if ($_POST['resume']) {
$fr = @fopen($cfg['savemailto'].'/tmp_'.substr($_POST['resume'],4), 'wb');
}
else {
$fr = @fopen($cfg['savemailto'].'/tmp_'.$mfile.'.txt', 'wb');
}
if ($fr === false) $err = 'Could not create or open temp file. Check directory permissions.';
}
if (!isset($err)) {
// WE'RE READY TO SEND!!!
$cnt = 0;
while ($item = readitem($f)) {
// pause if we're on a multiple of the pause interval
if ($cfg['pauseinterval'] > 0 && $cnt%(int)$cfg['pauseinterval'] == 0 && $cnt != 0) {
sleep((int)$cfg['pausetime']);
}
// fetch addresses and send
if (@mail($item['addr'], $subj, $body, $headers)) $succ++;
else $fail++;
$cnt++;
// update the temp file with resume info
if ($cfg['enableresume'] && $cfg['savemail']) {
rewind($fr);
fwrite($fr, $item['id']."\r\n");
}
}
}
if ($cfg['enableresume'] && $cfg['savemail']) {
// mailing is done, so we delete the temp file
// or, if this is a resume, delete the old temp file
fclose($fr);
if ($_POST['resume']) {
unlink($cfg['savemailto'].'/'.'tmp_'.substr($_POST['resume'],4));
}
else {
unlink($cfg['savemailto'].'/tmp_'.$mfile.'.txt');
}
}
}
}

Thank you in advance!
Errica

Fumigator
12-04-2008, 05:14 PM
The best way to avoid timing out when spamming is to stop spamming.

abduraooft
12-04-2008, 05:18 PM
The best way to avoid timing out when spamming is to stop spamming.That might be a newsletter as well.
A forum search in the server-side subforum for the keyword batches would give you some similar threads.

hinch
12-04-2008, 05:51 PM
this is an issue i'm having atm with one of my sites. luckily its a dedicated server so my quick work around was just simply to increase page time out.

Alternatively BCC is your friend just stack all the addresses into a BCC field and away you go



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum