[pmwiki-devel] Newsletter Throttling & Register Shutdown Function

The Editor editor at fast.st
Tue Oct 31 20:23:28 CST 2006


Finally, after much looking I discovered that the
register_shutdown_function is a php function, not a pmwiki one.  Read
the documentation and am trying to make heads of it with limited
success.  From the looks of it, solving my needs might be as simple as
adding a couple lines like this in the ZAP emailer function to begin
the ZAPnews mail sending routine once the form is submitted, and the
browser is moved on to the next page.

if (field == maillist) {   //in zapdata recipe
     register_shutdown_function('zapnews');
     $m .= "Message sent to queue. "; // message returned to screen
     continue;
     }

ZAPnews() {   //in zapnews recipe...
    blah, blah, blah
    sending newsletter code
	}

or better yet:

if (field == maillist) {
	$news="ZAPnewsl($_POST);";
	register_shutdown_function(create_function('',$news));
	ignore_user_abort()
    $m .= "Message sent to queue. "; // message
    continue;
    }

ZAPnews($formpost) {
    blah, blah, blah
    sending newsletter code
	}

(I wasn't sure the $_POST variables would be available in the
registered (child?) function. The little create_function trick is
supposed to allow you to pass stuff in to the registered function.
One thread also recommended the ignore_user_abort() line, just in
case.

But I also found these words:

--QUOTED--
Note that register_shutdown_function() does not work under Apache on
Windows platforms.  Your shutdown function will be called, but the
connection will not close until the processing is complete.  Zend
tells me that this is due to a difference between Apache for *nix and
Apache for Windows.
--ENDQUOTE--


Lastly, I found another little snippet which some say might work
better.  It seems this would work by putting a markup on the page
displayed after the newsletter form is submitted which produces output
like:

       <img src="maillist.php" width="1" height="1" border="0" alt="" />

on that page.  This combined with the maillist.php script below.  It
has it's pro's and con's.  The pro is it should work on any browser,
with no change to zap. (Are the $_POST values still available on this
second page?). Con is I'd have to add the markup on a second page...


--QUOTED--
Various commenters have described how this function doesn't work for
time-consuming background processing, because the webpage doesn't
close the connection.  The workaround using output buffering and
header('Connection: close'); seems to work, but the solution I prefer
is to put the background processing in a separate script which gets
included as a transparent gif.  The only caveat is, of course, if the
user has images turned off then the script won't be called.  Tested
successfully with IE6, Firefox 0.8, and Opera 7.11

<?php

  //maillist.php -- does the time-consuming zapnews() function

  function zapnews() {
      ... do all the news sending stuff here ...
      }

  register_shutdown_function('zapnews');
  header('Cache-Control: no-cache');
  header('Content-type: image/gif');
  header('Content-length: 85');
  print base64_decode('R0lGODlhAQABALMAAAAAAIAAAACAA'.
                       'ICAAAAAgIAAgACAgMDAwICAgP8AAA'.
                       'D/AP//AAAA//8A/wD//wBiZCH5BAE'.
                       'AAA8ALAAAAAABAAEAAAQC8EUAOw==');
  flush();
  exit;
?>

@-----------Page you want to add background processing to ---------@

<html>
<body>
<h1>Hello World</h1>

<!-- Call logger.php to do background processing -->
<img src="logger.php" width="1" height="1" border="0" alt="" />

</body>
</html>

@------------------------------------------------------------------@


Anyway, to make a long story short, I'm a bit confused.  Any
suggestions as far as which approach to use?  Or even if I'm
understanding this correctly?  If I can get it to work, this is going
to be a very nice mailing list manager recipe for PmWiki.  Thanks in
advance!

Cheers,
Caveman



More information about the pmwiki-devel mailing list