Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: three minus zero?
(Example: nine)

The Note You're Voting On

jakster at gmx dot net
17 years ago
To fork a process I use the following code

<?php

fclose
(STDOUT); //Close all output or it WON'T work
fclose(STDIN);
fclose(STDERR);

if(
pcntl_fork()) {
exit;
//Return to the caller
}

//Code to run in the background

pcntl_exec("/usr/bin/php",Array($_SERVER['argv'][1]));

?>

I call this script from my website with
<?php
function fork($script){ //run a forked php script relative to the document root. NO OUTPUT IS DISPLAYED!
global $config;
$cmd = "/usr/bin/php \"" . dirname($_SERVER['SCRIPT_FILENAME']) . "/includes/forked/forkHelper.php\" \"" . $script . "\"";
exec($cmd);
}
?>

<< Back to user notes page

To Top