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

The Editor editor at fast.st
Tue Oct 31 11:28:35 CST 2006


Hi all!

I happen to have a little bit of time opening up for me today and
tomorrow.  Would really like to make some headway on a PmWiki
newsletter/mailing list recipe.  Could someone please help me with one
little part?  I need to know how to launch a php function when a form
is submitted that runs independently, without tying up or being
dependentd on the submitter's browser.  Something that could run for
several hours or even days.

Details:  A zap form is submitted.  A particular field in the
submission triggers ZAP to call a newsletter module that runs
separately.  That function should return a very simple text value like
"message submitted to maillist queue" so ZAP can run the rest of it's
stuff and return a page to the browser.  However the newsletter
function should continue running after returning control to ZAP and
begin the long drawn out process of sending out the emails.

I can code the newsletter management in ZAP and the newsletter sending
in the news module (hopefully).  I just need to know how to set the
latter up so it can return processing to ZAP and yet continue sending
the emails separately.  If I could just get this much...  I think I
could get the rest done pretty quickly.

Below is a little snippet (posted before), that I adapted from
something Marc forwarded to me but don't think this is designed to run
the way I'm thinking (called by another function, triggered by a form
submission).  Nor does it return a text message.  And it doesn't
follow Pm's suggestion of using register_shutdown_function.  Could
someone help modify the appropriate lines?

Thanks a bunch!

Cheers,
Caveman


<?php

## This function is sent all needed email parameters from a zap form
containing: emaillist, emailfrom, emailsubject, emailbody.  ZAP does
all error checking, including checks to see if $ZAPnews is set, if
list exists, etc.  ZAP also can set an alerts variable and a
throttling variable.

SDV($ZAPnews, "true"); // used in ZAP emailer to check if zap news available
SDV($ZAPlistgroup, "MailList"); // default group for all pmwiki MailLists

function ZAPnews($list, $from, $subject, $message, $alerts=0, $throttle=20) {
    global $ZAPlistgroup, $ZAPadmin;

//Heres where I need help... This part is supposed to return to the
calling function without closing th php thread here.

    ob_implicit_flush(TRUE);
    @ignore_user_abort(true);
    sendGIF();
    ob_implicit_flush(FALSE);
    ob_start();

//This is the part I'll be using to send the emails. I can finish
debugging this, though suggestions welcome. Otherwise just ignore.

    $c = 0;
    if(PageExists("$ZAPlistgroup.$list")) {
         $page = ReadPage($xx);
         $contents = substr($page['text'], 3, -3);
         $r = explode("\n", $contents);
         foreach ($r as $recipient) {
              $c = $c + 1;
              if ($c == 1) $begin = substr($r, 0, strpos($r, "@")) . "@*****";
              $mergedbody = str_replace("{email}", $to, $body);
              mail($r, $subject, $mergedbody, "From: $from");
              if (($c == $alerts) && (isset($ZAPadmin[$list]))) {
                   $end = substr($r, 0, strpos($r, "@")) . "@*****";
                   $alertsubject = "ZAPnews alert";
                   $alerttime = strftime(%c, time());
                   $alertbody = "$subject sent, from $begin to $end by
$alerttime";
                   mail($ZAPadmin[$list], $alertsubject, $mergedbody,
"From: $from");
                   $c = 0;
                   }
              sleep($throttle);
              }

//used to close off the ob_start, whatever that is...

    ob_end_clean()
    }


//This function is called by the code above. I think it is supposed to
return a 1x1 pixel gif to the browser for display.  Not exactly what I
want.  Suppose I *could* try and design a little markup that actually
calls ZAPnews on the nextpage (after the form submits), use post/get
variables, to pass the needed data, etc.  But not sure this is really
what I want...

function sendGIF() {
   $img = base64_decode'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
   header('Content-Type: image/gif');
   header('Content-Length: '.strlen($img));
   header('Connection: Close');
   print $img;
 }



More information about the pmwiki-devel mailing list