title: Can't launch PHP background script
body: <p>I am trying to build a backup app for my website, and as part of that, I want to launch a PHP script in the background.  That way I don't have to worry about it timing out.  The strange part is that it works fine on my local computer, but when I copy it to my Hostgator website, it goes crazy.</p>
  
  <p>I've cobbled together a simple example...</p>
  
  <p>First, I created a simple PHP script:</p>
  
  <pre><code>&lt;?php
      echo 'Current PHP version: ' . phpversion() . "\n";
      echo 'Now:       '. date('Y-m-d') ."\n";
      echo "This is created by phpbg-back.php\n\n";
      echo "Current file: " . __FILE__;
  ?&gt;
  </code></pre>
  
  <p>I can run that script by SSH'ing into my host and running this command:</p>
  
  <pre><code># php phpbg-back.php 
  Current PHP version: 5.4.36
  Now:       2015-01-16
  This is created by phpbg-back.php
  
  ....
  </code></pre>
  
  <p>So, the script seems to work fine.  Now, I created a page that will launch the script as a background process:</p>
  
  <pre><code>&lt;?php
      if(isset($_GET["schedule"])) {  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Scheduling PHP Process&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Schedule....&lt;/h1&gt;
          &lt;p&gt;We are scheduling the process right now.  Here is the output:&lt;/p&gt;
          &lt;pre&gt;&lt;?php
              $command = "php phpbg-back.php &gt; phpbg-out.txt 2&gt;&amp;1 &amp;";
              echo "Command: " . $command . "\n";
              echo shell_exec($command);
          ?&gt;&lt;/pre&gt;
  
          &lt;a href="phpbg-front.php"&gt;Go back to the front page and check the output&lt;/a&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
      } else {
          echo "Invalid -- the page should have the schedule parameter set.\n\n";
          echo "Current file: " . __FILE__;
      }
  ?&gt;
  </code></pre>
  
  <p>Finally, I created a nice front page that should be able to view the output:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Example: PHP Background Process&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Example: PHP Background Process&lt;/h1&gt;
  
          &lt;h2&gt;Schedule&lt;/h2&gt;
          &lt;p&gt;Click this link to schedule the background process to run&lt;/p&gt;
          &lt;a href="phpbg-sched.php?schedule=true"&gt;Schedule&lt;/a&gt;
  
          &lt;h2&gt;Output&lt;/h2&gt;
  
          &lt;?php if(file_exists('phpbg-out.txt')) { ?&gt;
              &lt;pre&gt;&lt;?= file_get_contents('phpbg-out.txt') ?&gt;&lt;/pre&gt;
          &lt;?php } else { ?&gt;
              &lt;p&gt;No output file found&lt;/p&gt;
          &lt;?php } ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that when the script runs through this page it seems to totally ignore the script that I am passing to it.  It runs the current PHP page instead.  So, the output looks more like this (phpbg-out.txt):</p>
  
  <pre><code>Content-type: text/html^M
  ^M
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Scheduling PHP Process&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Schedule....&lt;/h1&gt;
          &lt;p&gt;We are scheduling the process right now.  Here is the output:&lt;/p&gt;
          &lt;pre&gt;Command: php phpbg-back.php &gt; phpbg-out.txt 2&gt;&amp;1 &amp;
  &lt;/pre&gt;
  
          &lt;a href="phpbg-front.php"&gt;Go back to the front page and check the output&lt;/a&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've tried all sorts of things to get it to work.  I tried adding bash -c in front of the command.  I've used the -f switch to make it pick the PHP script.  I'm not sure what else to try.</p>