[pmwiki-devel] Register shutdown...

Patrick R. Michaud pmichaud at pobox.com
Tue Nov 7 08:42:54 CST 2006


On Thu, Nov 02, 2006 at 04:56:39PM -0500, The Editor wrote:
> Ok, I've been really working hard at this, but can't seem to get past
> what is probably a simple little problem.
> 
> * EZ Mailing list management via zap and pmwiki.  Done.
> * Saves outgoing newsletters as pages in a pmwiki temp queue:  Done.
> * Markup that can be used to trigger sending of newsletter:  Done.
> * Code to Send Email:  Close to done--needs testing.
> * Way to do Sending Email in background?  HELP! HELP! HELP!
> 
> Here is part of the code I have right now in the ZAPnews recipe.
> Basically the markup works, BUT I get a blank page for 20 seconds and
> then the page reloads. I want the page to reload first, and then
> ZAPsendnews to operate quietly in the background. Again, I have Apache
> on XP if that makes a difference.
> 
> Can someone help me figure out what is wrong:
> 
> Markup('zapnews', '<{$var}', '/\(:zapnews:\\)/', ZAPnews());
> 
> function ZAPnews() {
> 	register_shutdown_function('ZAPsendnews');
> 	return "Newsletter being processed";
> 	}
> 
> function ZAPsendnews() {
> 	ignore_user_abort();
> 	sleep(20);
> 	ZAPsavepage("Test.Sleep1", "Hello World", "");
> 	die();
> 	}
> 
> This last function of course will be rewritten to do the actual
> sending once I get the processing to work right.  Thanks so much in
> advance.

Some notes:

1.  Functions called via register_shutdown_function often have the
    current directory changed.  Therefore, if you plan to use any
    of PmWiki's functions such as ReadPage, UpdatePage, etc., then
    the directory has to be restored prior to doing any processing.
    So you probably need:

        function ZAPnews() {
             register_shutdown_function('ZAPsendnews', getcwd());
             return "Newsletter being processed";
        }
        
        function ZAPsendnews($dir = NULL) {
            ignore_user_abort();
            if ($dir) { flush(); chdir($dir); }
            sleep(20);
            ZAPsavepage("Test.Sleep1", "Hello World", "");
        }

2.  Note that you probably don't need or want the die() function,
    you should let PHP terminate normally.


Pm       



More information about the pmwiki-devel mailing list