Это хороший способ показать вывод команд вашей оболочки в реальном времени:
<?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);
Эта функция понадобится для предотвращения буферизации вывода:
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');
}
}
Это doesn я работаю на каждом сервере, на котором я его пробовал, хотя хотел бы посоветовать, что искать в вашей php-конфигурации, чтобы определить, нужно ли вам вытаскивать волосы, пытаясь заставить этот тип поведения работать на вашем сервер! Кто-нибудь еще знает?
Вот фиктивный пример в простом PHP:
<?php
header("Content-type: text/plain");
disable_ob();
for($i=0;$i<10;$i++)
{
echo $i . "\n";
usleep(300000);
}
Надеюсь, это поможет другим людям, которые отправились туда по пути.