How to run shell script with live feedback from PHP?

Posted by Highway of Life on Stack Overflow See other posts from Stack Overflow or by Highway of Life
Published on 2012-03-20T17:27:04Z Indexed on 2012/03/20 17:29 UTC
Read the original article Hit count: 213

Filed under:
|
|

How would I execute a shell script from PHP while giving constant/live feedback to the browser? I understand from the system function documentation:

The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.

I'm not clear on what they mean by running it as a 'server module'. I attempted to run the script in the cgi-bin, but either I'm doing it wrong, or that's not what they mean.

Example PHP code:

<?php

system('/var/lib/script_test.sh');

Example shell code:

#!/bin/bash

echo "Start..."
for i in {1..10}
do
        echo "$i..."
        sleep 1
done
echo "Done."

© Stack Overflow or respective owner

Related posts about php

Related posts about shell