title: php shell_exec() help needed for running a script in the background
body: <p>My project calls for 3 php scripts that are run with if-else conditions. The first script is loaded on the index page of the site to check if a condition is set, and if it is, it calls for the second script. The second script check to see if other conditions are set and it finally calls for the last script if everything is good.</p>
  
  <p>Now I could do this by just including the scripts in the if statement, but since the final result is a resource hogging MySQL dump, i need it to be run independently of the original trigger page.</p>
  
  <p>Also those scripts should continue doing their things once triggered, regardless of the user actions on the index page.</p>
  
  <p>One last thing: it should be able to run on win and nix.</p>
  
  <p>How would you do this?</p>
  
  <p>Does the following code make any sense?</p>
  
  <pre><code>if ($blah != $blah-size){
  shell_exec ('php first-script.php &gt; /dev/null 2&gt;/dev/null &amp;'); 
   }
  //If the size matches, die
  else {
   }
  </code></pre>
  
  <p>Thanks a million in advance.</p>
  
  <p>UPDATE: just in case someone else is going through the same deal.
  There seem to be a bug in php when running scripts as cgi but command line in Apache works with all the versions I've tested.</p>
  
  <p>See the bug <a href="https://bugs.php.net/bug.php?id=11430" rel="nofollow">https://bugs.php.net/bug.php?id=11430</a></p>
  
  <p>so instead i call the script like this:</p>
  
  <pre><code>exec("php-cli mybigfile.php &gt; /dev/null 2&gt;/dev/null &amp;"); 
  </code></pre>
  
  <p>Or you could call it as shell. It works on nix systems but my local windows is hopeless so if anyone run it on windows and it works, please update this.</p>