Php – Flex: Output of a C file in real time via PHP+Flex

apache-flexPHP

I have a C executable (named myprogram). When I run it by ./myprogram I get some output statements on the standard output of my Linux shell.

I used run.php to get access to whatever is being printed to the standard output:

#run.php
<?php
$output = shell_exec('./myprogram');
echo $output;
?>

Then I called an HTTPService having id="service" to access this run.php file and I also set the text attribute of a TextArea to {service.lastResult}. When I run my Flex app, the interface kind of halts for a moment and then the TextArea displays all the 20 lines at once.

But if program is run from Linux shell they appear one by one.

Is there a way by which I can display a line as soon as it gets printed to standard output? This will then make the TextArea show the output in real time.

Or is Flex unable to do this? Rather how can a PHP program achieve such effect i.e. showing, whatever is being printed on standard output, concurrently in the browser in real time?

Update:
Let's make the question little more specific and/or simple.

myprogram outputs 20 lines each after some microseconds. I want only the first line of standard output to appear in TextArea of Flex or in the browser (but in real time) while the program may then continue running the program.

Doesn't look like simple 😛

Best Answer

HTTP doesn't work that way. You can simulate it with comet. In Java You can use BlazeDS for pushing data from server to flash client.