C'est une bonne façon d'afficher la sortie en temps réel de vos commandes shell :
<?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);
Vous aurez besoin de cette fonction pour empêcher la mise en mémoire tampon de la sortie :
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');
}
}
J'aimerais pouvoir donner des conseils sur ce qu'il faut rechercher dans votre configuration php pour déterminer si vous devez ou non vous arracher les cheveux en essayant d'obtenir ce type de comportement sur votre serveur ! Quelqu'un d'autre le sait ?
Voici un exemple fictif en PHP :
<?php
header("Content-type: text/plain");
disable_ob();
for($i=0;$i<10;$i++)
{
echo $i . "\n";
usleep(300000);
}
J'espère que cela aidera d'autres personnes qui ont cherché sur Google à venir ici.