This is a good way to show the output of your shell commands in real time:
<?php header("Content-type: text/plain"); // tell php to automatically flush after every output // including lines of output produced by shell commands disable_ob(); $command = 'rsync -avz /your/directory1 /your/directory2'; system($command);
You will need this function to prevent output buffering:
function disable_ob() { // Turn off output buffering ini_set('output_buffering', 'off'); // Turn off PHP output compression ini_set('zlib.output_compression', false); // Implicitly flush the buffer(s) ini_set('implicit_flush', true); ob_implicit_flush(true); // Clear, and turn off output buffering while (ob_get_level() > 0) { // Get the curent level $level = ob_get_level(); // End the buffering ob_end_clean(); // If the current level has not changed, abort if (ob_get_level() == $level) break; } // Disable apache output buffering/compression if (function_exists('apache_setenv')) { apache_setenv('no-gzip', '1'); apache_setenv('dont-vary', '1'); } }
It does not work on every server on which I tried it, although I would like to advise you to look in your php configuration to determine if you need to pull your hair out trying to get this type of behavior to work on your server! Does anyone else know?
Here is a dummy example in simple PHP:
<?php header("Content-type: text/plain"); disable_ob(); for($i=0;$i<10;$i++) { echo $i . "\n"; usleep(300000); }
Hope this helps other people who went here along the way.
Robb May 10 '11 at 21:30 2011-05-10 21:30
source share