title: Running PHP Process in the background from a Browser on Windows
body: <p>I'm a little sorry to ask this as I know that it has been asked many times before on here but all of the answers I have found do not work in my situation. Either I am doing something fundamentally wrong or I am trying to do something which is just not possible.</p>
  
  <p>I need to be able to fork a background process from a PHP file accessed via a web browser (served up by an Apache web server running on Windows). I need the foreground process to finish, and therefore the browser to stop waiting for the server whilst the forked process continues in the background. I am using PHP 5.3.</p>
  
  <p>I have tried numerous suggested solutions all with varying degree of fail:</p>
  
  <pre><code>shell_exec('D:\php5.3\php.exe sleep.php &gt; out 2&gt;out2' );
  </code></pre>
  
  <p>Whether ran through command line, or through browser, the foreground process did not complete until the background one did. Adding a "&amp;" in at the end didn't seem to make any difference</p>
  
  <pre><code>pclose(popen("start D:\php5.3\php.exe sleep.php","r"));
  </code></pre>
  
  <p>This one worked fine through command line, but when accessed via browser, it waited for both foreground and background processes to finish.</p>
  
  <pre><code>exec("nohup D:/php5.3/php.exe -f sleep.php &gt; out 2&gt;out2");
  </code></pre>
  
  <p>This didn't seem to work at all</p>
  
  <pre><code>$commandString = "start /b D:/php5.3/php.exe d:\\webroot\\other\\tests\\sleep.php"; 
  pclose(popen($commandString, 'r'));
  </code></pre>
  
  <p>Worked in command line, waited in browser</p>
  
  <pre><code>$WshShell = new COM("WScript.Shell");
  $oExec = $WshShell-&gt;Run("D:/php5.3/php-win.exe -f d:\\webroot\\other\\tests\\sleep.php", 0, false);
  </code></pre>
  
  <p>didn't work at all - hung when trying to fork the new process.</p>
  
  <p>Can anyone help? Am I missing something really obvious?!</p>
  
  <p>I know I can queue the tasks up in a database and run in batch, but I need this to operate in as close to real time as possible so do not want to introduce more delays by queueing things up that I can then only run max once a minute.</p>