How to interact between a web page and a real program

What do I have:

  • Program (C ++) on server (linux)
  • The program can be executed with command line parameters
  • The program ends after a while and produces continuous output ("log.txt")

What I want:

My idea is to have some kind of interaction with this program:

  • The user opens a website that displays some inputs (checkboxes, etc.).
  • After sending (POST) to the server, the program should be launched with the selected settings
  • When running the log.txt changes made by the program should be displayed to the user
  • At the end of the message, a message should appear (for example, "Done")

What would be the best approach? My current idea is to start a background process ( php execute background process ) and monitor the process id. However, I don't know how to dynamically control the process with php, how to show the user the log.txt output, or how to tell the user that the program is finished, because these things are not static but dynamic.

I am good with C ++ but my html and php skills are basic. Maybe I need another technology for this?


source to share

1 answer



$cmd = "your_program -{$_POST[option1]} -{$_POST[option2]}";

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("pipe", "w")
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo "<pre>";
if (is_resource($process)) {
    while ($s = fgets($pipes[1])) {
        print $s;
echo "</pre>";


echo 'Proc finished!';


as answered here but with a few changes.



All Articles