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);
}
?>