title: Populating $_SERVER when using popen to run a php script in background
body: <p>I'm using the following code to run the php script <code>email/send-emails.php</code> in the background:</p>
  
  <pre><code>if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
     $phpExec = str_replace('/', '\\', dirname(ini_get('extension_dir'))).'\php.exe';
     if(!file_exists($phpExec))
        throw new Exception('Could not find executable: '.$phpExec);
  } else {
     $phpExec = exec("which php-cli");
     if($phpExec{0} !== '/')
        $phpExec = exec("which php");
     if($phpExec{0} !== '/')
        throw new Exception('Could not find executable: '.$phpExec);
  }
  
  $exec = $phpExec.' email/send-emails.php';
  $cmd = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? 'start /B '.$exec : $exec.' &amp;';
  pclose(popen($cmd, 'r'));
  </code></pre>
  
  <p>This works beautifully on both Windows and Linux. The only problem is that <code>$_SERVER</code> is populated with completely different values in the calling script and in the email script. For instance, the keys <code>SERVER_PROTOCOL</code>, <code>SERVER_NAME</code>, and <code>REQUEST_URI</code> are missing in the email script. I guess this makes sense, since the calling script is served through Apache, while the the email-script is not(?).</p>
  
  <p>Is there a way to populate the missing values of <code>$_SERVER</code> when calling a php script using <a href="http://php.net/manual/en/function.popen.php" rel="nofollow"><code>popen</code></a>?</p>