PHP:passthru keeps waiting for the command to complete

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:

echo “Starting…”;
passthru(”/path/to/shell/script.sh > /dev/null &”);
echo “…Started”;
?>

Bookmark this post: technorati PHP:passthru keeps waiting for the command to complete delicious PHP:passthru keeps waiting for the command to complete stumbleupon PHP:passthru keeps waiting for the command to complete digg PHP:passthru keeps waiting for the command to complete facebook PHP:passthru keeps waiting for the command to complete yahoo PHP:passthru keeps waiting for the command to complete google PHP:passthru keeps waiting for the command to complete magnolia PHP:passthru keeps waiting for the command to complete reddit PHP:passthru keeps waiting for the command to complete windowslive PHP:passthru keeps waiting for the command to complete

Tags: ,

Related posts

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


  1. No Comments

Leave a Reply




/kapil/blog is Digg proof thanks to caching by WP Super Cache!