[pmwiki-devel] [pmwiki-users] Newsletter throttling

The Editor editor at fast.st
Thu Nov 2 14:04:55 CST 2006


In light of a couple recent posts, and because I could not get the
register_shutdown_function() to work properly, I decided to rethink
the process by which I will be sending emails.  Any input on either of
the following would be GREATLY appreciated:

A new approach:
When a newsletter zap form is submitted a wiki page will be created in
a TempMailList group which contains the full mailing list (in the text
of the page), and all the necessary newsletter information such as
timestamp, throttling info, from, subject, and email body (in the data
section of the page).  Once the page is created, control is returned
to the browser.

A (:zapnews:) markup will be written which returns a small 1x1
invisible gif and then starts the actual sendnews function in the
background.  This can be put on the same page as the newsletter form,
the next page viewed, the home page, or even the sidebar.  I will then
have to trust spiders/guests to hit those pages for long newsletters.
Those with cron access could probably call sendnews( ) directly.

When sendnews( ) is triggered, it gathers a list of all the pages in
the TempMailList group.  Each page is read, and current timestamp is
checked against the page's timestamp + $throttling time, to see if it
has waited long enough to be processed.

If so, it checks to see how many emails it should send and begins
sending the first $x emails.  After those emails are sent, they are
deleted from the email list, the timestamp is updated to the current
timestamp, and the page is resaved.  The next time the function is
triggered it repeats the process until all emails are saved--at which
point an email is sent to the administrator saying the newsletter has
been sent.

The same process is repeated for any other pages in the group.

This way if there was an error or the maillist stopped, it would be
restarted the next time the page was triggered (with in a worst case
scenario, a few people potentially being sent duplicates...).

You could also check on the progress of a mailing at any time by
simple going to the appropriate TempMailList page.

Cheers,
Caveman


P.S.  register_shutdown_function problem

As for the register_shutdown_function problem I had, somehow this code
did not relinquish control back to the browser (XP/Apache) and
therefore doesn't work.  The above idea is probably a better solution
than what I first had in mind, but sure would like to know where my
problem is...  Pardon the snips and shortcuts:

function ZAPengine($ZAPflag = 0) {
     ... init stuff ...
     foreach ($_POST as $field => $value) {
     ... check various options ...

     if ((isset($ZAPmodule[mail])) && (strpos($ZAPmodule[mail],
$field))) ZAPmail($field, $value);  //sends field=value pair to
zapmail module
     ...rest of recipe, page reloaded, etc...
     }


function ZAPmail($field, $value) {
     global $WorkDir, $WikiDir, $pagename, $MessagesFmt, $m, $ZAPprofiles;
     ...checks for from, subject, etc...
     if ($field == "emailnews") {
          register_shutdown_function('sendnews', $_POST);
          //did call sendnews but blank page for 20 seconds
          //did not return control to browser first.
          $m .= "Message sent to queue. "; //did show up
          return; // return to engine to finish form processing and reload page
          }
     ...also process emailto's and simple emaillists...
     return; // return to engine to finish form processing and reload page
     }

function sendnews($formpost) {
     ignore_user_abort();
     global $ZAPlistgroup, $ZAPadmin;
     sleep(20);  //it did sleep
     ZAPsavepage("Test.Sleep", "Hello World", "");  //page created--my
debug test
     die();
     }



More information about the pmwiki-devel mailing list