title: PHP - Call external programs and show progress
body: <p>I have a PHP script that takes the fields of a form to make 3 alternated program calls, where the output of the first one is the input of the second one and so on.</p>
  
  <p>The problem is that I need to display the progress of each program call, nothing to complicated, I just like to show 3 different messages:</p>
  
  <ul>
  <li>System call N waiting.</li>
  <li>System call N in execution.</li>
  <li>System call N finished.</li>
  </ul>
  
  <p>I´m trying to do that with the different PHP functions like exec(), popen() or proc_open() but with these ones the browser waits until each call finish.
  The whole system calls don´t take more than 5 minutes, maybe 3 or 4, so, it would also be good to place a timer in each call, maybe 1.5 minutes, and if the call takes more that that time, kill the current system call, skip the following calls and show an error message.</p>
  
  <p>Do you have any idea? Maybe a combination of ajax and javascript can be a solution. Thanks in advance.</p>
  
  <pre><code>&lt;?php
  /*
    System Calls
    This file is required in another main script
    $projectPath and $projectName defined in the main script
  */
  
  //$mainHome = getcwd();
  
  $home = $projectPath . $projectName;
  $temp = $home . "/temp/";
  $calls = $temp . "CALLS";
  
  $threads = array();
  
  if(is_dir($temp)){
      //chdir($temp);
      $FILE = fopen($calls, "r");
      while(($call = fgetcsv($FILE)) !== FALSE) {
          //print_r($call);
          $threads[] = implode(" ", $call);
      }
  }
  
  //print_r($threads);
  
  $descriptorspec = array(0 =&gt; array("pipe","r"),
                          1 =&gt; array("pipe","w"),
                          2 =&gt; array("file","./phpError.log","a")
  );
  
  for ($a=0; $a&lt;count($threads); $a++) {
      print $threads[$a] . "&lt;br/&gt;&lt;br/&gt;";
      exec($threads[$a])
      //$res = proc_open($threads[$a], $descriptorspec, $pipes, $temp);
  }
  
  //chdir($mainHome);
  </code></pre>
  
  <p>?></p>