0

I am building a web interface for a C# app. Due to the project specifications, I cannot use ASP.Net to do that, so I'm using HTML.

My C# app has some console output that displays the current status of the app. I want to display that output on my web page using a PHP script. I am using an iframe like so:

<iframe id="appLog" src="php/startApp.php"></iframe>

and I test my PHP script by pinging google 5 times:

<?php
$cmd = "ping 127.0.0.1 -c 5";
ob_implicit_flush(true);
ob_start();
echo '<pre>';
ob_flush();
$proc = popen($cmd, 'r');
while (!feof($proc))
{
    echo fread($proc, 4096);
    ob_flush();
}
echo '</pre>';
ob_end_flush();
?>

However, theping output is only displayed after the process completes. I have tried multiple approaches already, and in every one I can only see the command's output after the process is done. I need the output to be displayed in real-time in a browser window.

Is there any way I can accomplish this in PHP?

Mu3
  • 169
  • 1
  • 9
  • Why you don't use a database to store output of the console and read it in AJAX ? – Thomas Rollet Oct 31 '17 at 12:13
  • @iainn I have tried the approach suggested there, and it does not work for me. – Mu3 Oct 31 '17 at 12:14
  • @ThomasRollet I cannot use a database because I am developing for an embedded system with limited capabilities. – Mu3 Oct 31 '17 at 12:15
  • you could do something similar but not qite as clean, EG: redirect STDOUT of your process to a text file, read the file from PHP, no db required. – Zachary Craig Oct 31 '17 at 12:39
  • I think you could keep those messages in ram by adding the messages into a singelton class. Now on a Ajax request you could theoretically send the client alle messages it needs. – Werner Oct 31 '17 at 12:41

0 Answers0