Invoke external shell script from PHP and get its process ID

Christian Studer picture Christian Studer · Sep 24, 2009 · Viewed 22k times · Source

How can I invoke an external shell script (Or alternatively an external PHP script) from PHP itself and get its process ID within the same script?

Answer

Boris Guéry picture Boris Guéry · Sep 24, 2009
$command =  'yourcommand' . ' > /dev/null 2>&1 & echo $!; ';

$pid = exec($command, $output);

var_dump($pid);