in reply to Speeding up a mailing list script

Ok, so here are the test results

Test conditions -
50.000 emails
30k message
type - multipart
server time out time - average after approx 60mins

Results
1. using the original script at 11.59am (nyc time) i managed to send 10.600 emails
2. using the NEW script (here below) at 4.00am (nyc time) i sent 9.800 emails
3. using the original script at 13.10am (nyc time)sending an empty mail (0k), by mistake, i sent 19.400 emails
4. using the NEW script at 3.00am (nyc time) BUT with the open MAIL and close MAIL tags positioned just outside the loop i managed to have the script process all the mail but i received NONE.

Any suggestions?

CODE
#!/usr/bin/perl read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%0D%0A/|/g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($in{$name}) { $in{$name} = $in{$name}.",".$value; } else { $in{$name} = $value; } } $in{'txt_message'} =~ s/\|/%0D%0A/g; $in{'txt_message'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1 +))/eg; $text_message = $in{'txt_message'}; $in{'html_message'} =~ s/\|/%0D%0A/g; $in{'html_message'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($ +1))/eg; $html_message = $in{'html_message'}; $totalEmails = $in{'rightrange'} - $in{'leftrange'} + 1; $time_start = time() + $in{'time_diff'}*3600; $lock = "2"; $pid = fork(); print "Content-type: text/html \n\n fork failed: $!" unless defined $p +id; if ($pid) { print "Content-type: text/html \n\n"; print "<html><head><title>List Administration</title></head><body> <br><br><br><center> Congratulations!<br>The mailing has been started. You will receive + a confirmation e-mail when the mailing has been completed. <P><FORM><INPUT TYPE=BUTTON VALUE=\"Back\" onClick=\"history.go(-1 +)\"></form></center></body></html>"; exit(0); } else { close (STDOUT); $count = 0; open(LIST,"$in{'list_dir'}/$in{'list'}/$in{'list'}.txt"); if ($lock){flock(LIST, $lock);} @addresses=<LIST>; close(LIST); $text_message =~ s/(.{60}\s)/$1\n/g; my @boundaryv = (0..9, 'A'..'F'); srand(time ^ $$); for (my $i = 0; $i++ < 24;) { $boundary .= $boundaryv[rand(@boundaryv)]; } ############# my $htmlhead =<<EOHTMLHEAD; Content-type:text/html\n EOHTMLHEAD my $multihead =<<EOMULTIHEAD; MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Next_Part_$boundary" ------=_Next_Part_$boundary Content-type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable EOMULTIHEAD my $multipart =<<EOMULTIPART; ------=_Next_Part_$boundary Content-type: text/html; charset="base64" Content-Transfer-Encoding: quoted-printable EOMULTIPART ############ for ($count = ($in{'leftrange'} - 1); $count < $in{'rightrange'}; $cou +nt++) { $member = @addresses[$count]; chomp($member); open (MAIL, "|$in{'mailprog'} -t") || die "Can't open $in{'mailprog'}! +\n"; my $textremove =<<EOTEXTREMOVE; --------------------------------------------------------------------- Text remove... --------------------------------------------------------------------- EOTEXTREMOVE my $htmlremove =<<EOHTMLREMOVE; <BR><BR> ---------------------------------------------------------------------< +br> HTML remove... ---------------------------------------------------------------------< +br><br> EOHTMLREMOVE print MAIL "From: $in{'adminMail'}\n"; print MAIL "To: $member\n"; print MAIL "Subject: $in{'subject'}\n"; my $msg = ''; $msg .= $htmlhead if $in{'type'} eq "html"; $msg .= $texthead if $in{'type'} eq "textpart"; $msg .= $multihead if $in{'type'} eq "multipart"; unless($in{'type'} eq 'html') { $msg .= "$text_message\n\n"; $msg .= $textremove if $in{'remove_notice'} eq "1"; } $msg .= $multipart if $in{'type'} eq "multipart"; unless($in{'type'} eq 'text') { $msg .= "$html_message\n"; $msg .= $htmlremove if $in{'remove_notice'} eq "1"; } print MAIL $msg; if (int($count/100)*100 == $count) { $time_now = time() + $in{'time_diff'}*3600; open(LOG, ">$in{'list_dir'}/$in{'list'}/log_sent.txt"); if ($lock){flock(LOG, $lock);} $status = $count - $in{'leftrange'} + 1; print LOG "$time_start" . "::" . "$totalEmails" . "::" . "$status" + . "::" . "$time_now"; close(LOG); } close MAIL; } } $time_now = time() + $in{'time_diff'}*3600; open(LOG, ">$in{'list_dir'}/$in{'list'}/log_sent.txt"); if ($lock){flock(LOG, $lock);} print LOG "$time_start" . "::" . "$totalEmails" . "::" . "$count" +. "::" . "$time_now" . "::end"; close(LOG); open (MAIL, "|$in{'mailprog'} -t"); print MAIL "From: $in{'adminMail'}\n"; print MAIL "To: $in{'adminMail'}\n"; print MAIL "Subject: Congratulations!\n\n"; print MAIL "Congratulations!\nThe mailing was successfully sent to + $totalEmails people by $ENV{'REMOTE_ADDR'}.\nMailing started at $tim +e_start and ended at $time_now.\nHere is what was sent:\n\n-----\n\n" +; print MAIL "Type - $in{'type'}\n\n"; print MAIL "Subject: $in{'subject'}\n\n"; if ($in{'type'} eq 'html') { print MAIL "$in{'html_message'}\n\n-----"; } else { print MAIL "$in{'text_message'}\n\n-----"; } close (MAIL); exit;


thanks
Adrien