title: Forking in PHP on Windows
body: <p>We are running PHP on a Windows server (a source of many problems indeed, but migrating is not an option currently).  There are a few points where a user-initiated action will need to kick off a few things that take a while and about which the user doesn't need to know if they succeed or fail, such as sending off an email or making sure some third-party accounts are updated.  If I could just fork with <code>pcntl_fork()</code>, this would be very simple, but the PCNTL functions are not available in Windows.</p>
  
  <p>It seems the closest I can get is to do something of this nature:</p>
  
  <pre><code>exec( 'php-cgi.exe somescript.php' );
  </code></pre>
  
  <p>However, this would be far more complicated.  The actions I need to kick off rely on a lot of context that already will exist in the running process; to use the above example, I'd need to figure out the essential data and supply it to the new script in some way.  If I could fork, it'd just be a matter of letting the parent process return early, leaving the child to work on a few more things.</p>
  
  <p>I've found a few people talking about their own work in getting various PCNTL functions compiled on Windows, but none seemed to have anything available (broken links, etc).</p>
  
  <p>Despite <a href="https://stackoverflow.com/questions/601670/whats-the-best-way-to-fork-thread-in-php-on-win">this question</a> having practically the same name as mine, it seems the problem was more execution timeout than needing to fork.  So, is my best option to just refactor a bit to deal with calling php-cgi, or are there other options?</p>
  
  <p>Edit: It seems <code>exec()</code> won't work for this, at least not without me figuring some other aspect of it, as it waits until the call returns.  I figured I could use <code>START</code>, sort of like <code>exec( 'start php-cgi.exe somescript.php' );</code>, but it still waits until the other script finishes.</p>