php shell_exec with realtime updating

EduAlm picture EduAlm · Dec 3, 2011 · Viewed 9.5k times · Source

I have this shell program that I want to execute by php. The problem is that it can potentially take a long time, and as of that I need it to have real-time updating to the user's browser.

I read that I may need to use popen() to do that, but I am sort of (ok, I really am :P) a PHP noob and can't figure out how I may be able to do it.

Would appreciate any help!

Answer

RolandasR picture RolandasR · Dec 3, 2011
if( ($fp = popen("your command", "r")) ) {
    while( !feof($fp) ){
        echo fread($fp, 1024);
        flush(); // you have to flush buffer
    }
    fclose($fp);
}