2

My project build process involves complex tasks & they are time consuming. If I execute Phing command line, I want end-user to display real time information on browser, about what's happening about the build (step by step).

Using exec() will execute the process and will print the output, but I don't want such behavior.

Is there a way where I can capture data step by step?

4

1 回答 1

1

Phing Output to Browser in Real-time

You want to send Phing output/status lines directly to a browser in real-time. To asynchronously send status from Phing output to a browser you can use the following example code.

1) Example using pipe.php of Phing + System("...") CMD

The following is an example usage of php system() and phing command line in combination

<?php system("phing -args... | ./pipe.php"); ?>

2) Receiving Phing Output in a Browser

Visit the following URL to receive output:

Console: http://www.pubnub.com/console?channel=phing-out

3) Sending Phing-to-Browser CMD Line Pipe Example (pipe.php)

Copy this into a pipe.php file and make it chmod +x pipe.php executable. Also download this dependency: https://github.com/pubnub/php

#!php
<?php
    ## 
    ##   -- pipe.php -- 
    ##
    ## command | ./pipe.php
    ##

    ## Create new TCP Session Route (send-to-browser)
    require_once('Pubnub.php');
    $pubnub = new Pubnub( "demo", "demo", "", false );

    ## Load STDIN String
    $handle = fopen( 'php://stdin', 'r' );
    while($phing_out = fgets( $handle, 512 )) {
        $phing_out = trim($phing_out);
        $pubnub->publish(array(
            'channel' => 'phing-out',
            'message' => $phing_out
        ));
    }
    fclose($handle);
?>

That's it! Note that this is only a starting point and if you want to go further you may need to send the output into your own HTML file. See more details below:

Receive Output in your Own HTML File (Browser)

If you'd like to receive Output in your own HTML file, you'll want to refer to the following GitHub Repository: https://github.com/pubnub/javascript

<div id=out></div>
<script src=http://cdn.pubnub.com/pubnub-3.5.3.min.js ></script>
<script>(function(){

    // Init
    var pubnub = PUBNUB.init({
        publish_key   : 'demo',
        subscribe_key : 'demo'
    })

    // HTML Display Node (for visual output)
    var out = pubnub.$('out')

    // TCP Receive
    pubnub.subscribe({
        channel : "phing-out",
        message : function(m){ out.innerHTML += m + "<br>" }
    })

})();</script>
于 2013-07-08T21:30:07.813 回答