run-process-with-realtime-output-in-php

This is a nice way to show real time output of your shell commands:

<?php
header("Content-type: text/plain");

// tell php to automatically flush after every output
// including lines of output produced by shell commands
ob_implicit_flush(true);
ob_end_flush();

$command = 'rsync -avz /your/directory1 /your/directory2';
system($command);

It doesn’t work on every server I have tried it on though, I wish I could offer advice on what to look for in your php configuration to determine whether or not you should pull your hair out trying to get this type of behavior to work on your server! Anyone else know?

Here’s a dummy example in plain PHP:

<?php
header("Content-type: text/plain");

ob_implicit_flush(true);
ob_end_flush();

for($i=0;$i<10;$i++)
{
    echo $i . "\n";
    usleep(300000);
}

I hope this helps others who have googled their way here.

 

http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s