<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Your talk of an email alias has intrigued me, =).</FONT></DIV>
<DIV><FONT size=2>I'll try and read up on them.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I managed to solve the problem of the Catalyst app crashing, 
using some of the advice given.</FONT></DIV>
<DIV><FONT size=2>- To queue the emails in the background,</FONT></DIV>
<DIV><FONT size=2>- To try not to waste memory.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I stopped trying to be all modern perl, and gave up using 
Email::Stuffer.</FONT></DIV>
<DIV><FONT size=2>Instead, I went back to oldskool perl, and used:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>my $mailprog= 'usr/lib/sendmail -i -t -odq -f 
myreturn</FONT><FONT size=2>@emailaddress.com</FONT><FONT size=2>'</FONT><FONT 
size=2>;</FONT></DIV>
<DIV><FONT size=2>open(MAIL,"|$mailprog");</FONT></DIV>
<DIV><FONT size=2>print MAIL $email;</FONT></DIV>
<DIV><FONT size=2>close MAIL;</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Using the "-odq" flag, adds it to the exim4 mail queue without 
waiting for it to send.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>When I was using Email::Stuffer in a loop, I gather it was 
creating an object...so it could have been creating 3000 objects - maybe that 
caused memory issues, which could have been responsible for the 
crash.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>So this time, I had my email source code as a text file, that 
was just read in once at the start of the script,</FONT></DIV>
<DIV><FONT size=2>and the only thing left to do in the foreach loop (now 
iterating over a list of userids to email), was to add&nbsp;in the TO line - 
with the name and email address.</FONT></DIV>
<DIV><FONT size=2>Rather than do a find and replace (via pattern 
matching)&nbsp;of the email source&nbsp;3000 times to substitute in a TO 
address, I merely concatenated the TO line onto the rest of the email source, 
during each iteration... in the hope it would reduce processing.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>my $toline='To: "'.$id_fullname{$userid}.'" 
&lt;'.$id_email{userid}.'&gt;';</FONT></DIV>
<DIV><FONT size=2>my $email=$toline."\n".$emailsource;</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>So what was the result?</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>The result was - all emails were successfully 
queued.</FONT></DIV>
<DIV><FONT size=2>Because my last attempt had sent the first 1100 or so emails, 
I was only sending around 1900 emails this time.</FONT></DIV>
<DIV><FONT size=2>The Catalyst app did not crash - the plackup process stayed 
up.</FONT></DIV>
<DIV><FONT size=2>However - the Catalyst app was unable to give any response to 
a web browser until all messages had been queued - which took about 8 minutes to 
be fair (going by the time given in the dates in the mail queue - where the 
first email has a time of 3:31pm and the last 3:39pm).</FONT></DIV>
<DIV><FONT size=2>Even other subroutines, mapped to different urls, would not 
give a response to a web browser, until the exim mail queue had been fully 
populated.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>It would seem then, although I succeeded in not crashing the 
server or Catalyst App,</FONT></DIV>
<DIV><FONT size=2>the Catalyst App doesn't seem to want to give responses to web 
browsers while it's doing this stuff.</FONT></DIV>
<DIV><FONT size=2>I was hoping merely queuing emails instead of sending them, 
meant there was nothing much to wait on.</FONT></DIV>
<DIV><FONT size=2>It seems I will indeed need a separate script in the 
background to send these things, leaving the main Catalyst App&nbsp;free 
to&nbsp;handle all the web browser requests.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>----- Original Message ----- </FONT>
<DIV><FONT size=2>From: "Luca Ferrari" &lt;</FONT><A 
href="mailto:fluca1978@infinito.it"><FONT 
size=2>fluca1978@infinito.it</FONT></A><FONT size=2>&gt;</FONT></DIV>
<DIV><FONT size=2>To: "The elegant MVC web framework" &lt;</FONT><A 
href="mailto:catalyst@lists.scsys.co.uk"><FONT 
size=2>catalyst@lists.scsys.co.uk</FONT></A><FONT size=2>&gt;</FONT></DIV>
<DIV><FONT size=2>Sent: Friday, December 11, 2015 11:12 AM</FONT></DIV>
<DIV><FONT size=2>Subject: Re: [Catalyst] Sending 3000 
emails.</FONT></DIV></DIV>
<DIV><FONT size=2><BR></FONT></DIV><FONT size=2>On Thu, Nov 26, 2015 at 4:32 PM, 
Andrew &lt;</FONT><A href="mailto:catalystgroup@unitedgames.co.uk"><FONT 
size=2>catalystgroup@unitedgames.co.uk</FONT></A><FONT size=2>&gt; 
wrote:<BR>&gt; ....I just want to know why the whole FastCGI Plack loaded 
Catalyst app came<BR>&gt; down half way through,<BR>&gt; and how I can have a 
Perl script process sending 3000 emails without that<BR>&gt; happening every 
time, =S.<BR>&gt;<BR><BR>As pointed out already the main problem here is that 
you are trying to<BR>do stuff (sending email) within the app thread, that is you 
are<BR>breaking the app design and should use a batch/background thread to 
do<BR>intensive work (even reading all the emails from database could be 
a<BR>problem, depending on how you do the query and how optimized is 
the<BR>database).<BR>I would pick up at least an email alias, that can be 
easibly<BR>auto-generated and updated each time a new user joins. This way 
you<BR>are at least hiding the 3000+ receivers behind a single email, 
letting<BR>the email software to do the stuff it has been built for.<BR>The next 
step would be to use a mailing list, internal or external.<BR>The only reason I 
could see for looping thru every email address could<BR>be to store in the 
database the result of the sending process, which<BR>is in my opinion 
worthless.<BR><BR>Luca<BR><BR>_______________________________________________<BR>List: 
</FONT><A href="mailto:Catalyst@lists.scsys.co.uk"><FONT 
size=2>Catalyst@lists.scsys.co.uk</FONT></A><BR><FONT size=2>Listinfo: </FONT><A 
href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst"><FONT 
size=2>http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</FONT></A><BR><FONT 
size=2>Searchable archive: </FONT><A 
href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/"><FONT 
size=2>http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</FONT></A><BR><FONT 
size=2>Dev site: </FONT><A href="http://dev.catalyst.perl.org/"><FONT 
size=2>http://dev.catalyst.perl.org/</FONT></A></BODY></HTML>