I wanted to execute (in background) a shell script from a PHP program. I wrote the following code for the same:
echo “Starting…”;
passthru(”/path/to/shell/script.sh &”);
echo “…Started”;
?>
But unfortunately, the results were not what I had expected. The PHP script keeps running untill the script.sh exits.
$> php -q try.php
Starting…
Fortunately enough, I found the solution pretty soon. The trick is to redirect the output to /dev/null.
Changing the above code to the following worked for me:
Tags: howto, phpecho “Starting…”;
passthru(”/path/to/shell/script.sh > /dev/null &”);
echo “…Started”;
?>













0 Responses to “PHP:passthru keeps waiting for the command to complete”
Leave a Reply