[UPHPU] Forking A Script [SOLVED]
Ken Snyder
ksnyder at coremr.com
Mon Jul 23 15:21:26 MDT 2007
John David Anderson wrote:
> You may not need to fork. Try appending an ampersand to the end of the
> command:
>
> $ php doReportScript.php &
>
> That'll run the process in the background (that way PHP won't wait for
> a return).
>
> -- John
> ...
Yay!! After more googling for "php background processing" and lots of
testing, I found a working cross-platform background-processing method
using functions popen() and pclose(). (Never heard of those
functions!) It relies on the command line ampersand concept.
Explained here:
http://robert.accettura.com/archives/2006/09/14/asynchronous-processing-with-php/
See below for the heart of the idea. Now if we can just spread the
word--this is a question that has come up on a zillion forums!
-- Ken
if (is_windows()) {
// windows uses "start /b"
pclose(popen('start /b ' . $call, 'r'));
} else {
// *nix uses "/dev/null &"
pclose(popen($call . ' /dev/null &', 'r'));
}
echo "<p>Called "$call" without waiting for a return value</p>";
More information about the UPHPU
mailing list