title: PHP `exec` in the background but get STDOUT
body: <p>I'm trying to execute a command (in both Windows and Linux) via PHP. My target is to have multiple instances of the command running at the same time (hence background) but I need to grab the output of each also. </p>
  
  <p>This doesn't work as the output cannot be grabbed.</p>
  
  <pre><code>function execInBackground($cmd) { 
      if (substr(php_uname(), 0, 7) == "Windows"){ 
          pclose(popen("start /B ". $cmd, "r"));  
      } 
      else { 
          exec($cmd . " &gt; /dev/null &amp;");   
      } 
  }
  </code></pre>
  
  <p>Will forking help me? I saw <a href="https://stackoverflow.com/questions/14412190/php-exec-in-background-using-is-not-working">PHP exec in background using &amp; is not working</a> too but again where to get the output?</p>
  
  <p>Any ideas would be great!</p>
  
  <p>EDIT: We are using PHP v5.2, other PHP versions cannot be used!</p>