title: How to wait for a process executed by proc_open() in php?
body: <p><strong>please after reading this question , do not say that it is copied.I have already searched on web but none of the solution worked for me.</strong></p>
  
  <p><strong>What i am  doing :-></strong><br>
  I am taking a source file (say .c) through php by running apache server on local host.I am saving that file in "/code/" directory and compiling and executing this source file using proc_open() in php.Now i want to wait main php script until the process created by "proc_open()" terminates, so i used "pcntl_waitpid()".But i think there is a problem in using "pcntl_waitpid()" because the script after the "pcntl_waitpid()" is not executing.
  Process created by "pcntl_waitpid()" takes input from "/code/input.txt" file and gives output to "/code/output.txt" file, so for redirecting purpose i am using proc_open() , so that i can easily redirect streams.  </p>
  
  <p><strong>My machine configuration:-</strong><br>
  OS -> Ubuntu 12.04 LTs<br>
  PHP 5.3.10<br>
  APACHE 2.2.22<br>
  Running on local host  </p>
  
  <p><strong>Permissions :-</strong><br>
  /code -> 777<br>
  Folder where main php file resides -> 777 (I know that 777 is not good due to security reasons , but as i am running script on local server so i have no problem with these permissions.)   </p>
  
  <p><strong>What i want :-</strong>
  Can any one tell me any way so that i can stop main php script until the process created by proc-open() terminates or if anyone can tell me other way to meet my requirement of redirection ?  </p>
  
  <p><strong>Here is a part of the code :</strong></p>
  
  <pre><code>$descriptors = array(
              2 =&gt; array("pipe","w")
          );
  
  
  
  
          $process = proc_open($cmd,$descriptors,$pipes,$code);
  
          sleep(2);
  
          if(is_resource($process))
          {
              $status = proc_get_status($process);
              $pid = $status ["pid"];
  
              echo getmypid()."&lt;br /&gt;";
  
  
              echo $pid;
  
              if(pcntl_waitpid($pid,$child_status) == -1)
              {
                  fclose($pipes[2]);
                  proc_close($process);
                  exit("Sorry!Unable to compile the source_file.\n");
  
  
              }
  
  
              while(!file_exists("/code/test"))
              {
  
                  proc_close($process);
                  echo stream_get_contents($pipes[2]),"\n";
                  fclose($pipes[2]);
                  exit("Sorry!Unable to compile the source_file.\n");
              }
  
              echo "Compiled Successfully!\n";
              echo "Running test cases...\n";
  
              fclose($pipes[2]);
  
              proc_close($process);
  
          }
          else
          {
              exit("Sorry!Unable to compile the source_file.\n");
          }
  </code></pre>
  
  <p><strong>THANK YOU!</strong></p>