I am creating a PHP script that will be run via the command line. As part of this script, there are times where I might need to spawn/fork a different script that could take a long time to complete. I don't want to block the original script from completing. If I were doing this with JavaScript, I could run AJAX requests in the background. That is essentially what I am trying to do here. I don't need to know when the forks complete, just that they start and complete themselves.
How can I run these PHP scripts asynchronously?
foreach ($lotsOfItems as $item) {
if ($item->needsExtraHelp) {
//start some asynchronous process here, and pass it $item
}
}
int pcntl_fork ( void )
details : http://php.net/manual/en/function.pcntl-fork.php
related question : PHP: What does pcntl_fork() really do?
details: http://www.php.net/manual/en/intro.pcntl.php
Looking the user contributed notes on exec, it looks like you could use it, check out:
http://de3.php.net/manual/en/function.exec.php#86329