#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Auckland
    Posts
    93
    Rep Power
    24

    [phing] Real time output from terminal to browser


    Hello,
    I am using "phing" to automate build process. I'm execcuting phing thrugh exec() which

    PHP Code:
    <?php exec("/usr/local/bin/phing"$output); ?>
    This does gives me expected output but not real-time; but the same if I execute through terminal ,it gives me step by step output like .. preparing your build, ..copying files.. likewise..

    I tried using various methods "ob_implicit_flush(1)" , proc_open() but didn't helped me..

    Can some one guide me how to proceed about this?

    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,115
    Rep Power
    9398
    Since exec() and that family of functions returns the entire output at once you'll need to use process control functions (proc_open(), popen(), etc) to (1) open up the process, (2) read output as it's generated by the program, and (3) use the various output-flushing functions to output each line as it's sent back to the script.
    Code:
    $p = proc_open with stuff
    // be sure to grab stdout as a pipe
    while !feof(the pipe) {
    	read a line
    	output the line and flush
    }
    close the pipe
    close the process
    If you need to monitor stderr too then your solution should involve "selecting" from the two streams as output is available - that way you don't let one build up while you read from the other. Ask me if you need that and I can show you what that looks like.

    Keep in mind that what the browser shows is up to the browser: it's quite possible for PHP to output things in real time but if the browser doesn't want to show it as such then it won't.

    If that ends up being a problem then you might have to get tricky: a socket would be ideal (eg, WebSockets) but AJAX would be one awkward way of doing it too.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Auckland
    Posts
    93
    Rep Power
    24
    Thank your for your detailed analysis. Ya, even I tried proc_open() but as you said its upto the browser so could be a limitation.

    I will try with other two ways & will share script if I get stuck in that.

    Thanks once again..

    Ryand


    Originally Posted by requinix
    Since exec() and that family of functions returns the entire output at once you'll need to use process control functions (proc_open(), popen(), etc) to (1) open up the process, (2) read output as it's generated by the program, and (3) use the various output-flushing functions to output each line as it's sent back to the script.
    Code:
    $p = proc_open with stuff
    // be sure to grab stdout as a pipe
    while !feof(the pipe) {
    	read a line
    	output the line and flush
    }
    close the pipe
    close the process
    If you need to monitor stderr too then your solution should involve "selecting" from the two streams as output is available - that way you don't let one build up while you read from the other. Ask me if you need that and I can show you what that looks like.

    Keep in mind that what the browser shows is up to the browser: it's quite possible for PHP to output things in real time but if the browser doesn't want to show it as such then it won't.

    If that ends up being a problem then you might have to get tricky: a socket would be ideal (eg, WebSockets) but AJAX would be one awkward way of doing it too.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Location
    Auckland
    Posts
    93
    Rep Power
    24
    Originally Posted by ryand
    Thank your for your detailed analysis. Ya, even I tried proc_open() but as you said its upto the browser so could be a limitation.

    I will try with other two ways & will share script if I get stuck in that.

    Thanks once again..

    Ryand
    Just an update, if I use proc_open ping works just fine on browser. but this is not same with phing? so shall we conclude that its command based n not browser based ?

IMN logo majestic logo threadwatch logo seochat tools logo