title: Seeing multiple invocations for long-running HTTP GET request
body: <p>I have a long-running query, it typically takes about 10 seconds or so to complete. While it's running, there will be an additional request, usually about 6 or 7 seconds later. This additional request is like the first one, except that <code>Referer</code> (sic) is not present as a server header.</p>
  <p>While the page loads okay, I can confirm that it's doing twice the work required to handle the first request, and then the new one which comes while the first is still processing. I'm not sure which request actually gets back with the response, but if I send back <code>202 (Accepted)</code> as a status for either the first or second request, it just hangs and times out.</p>
  <p>Here's an outline of the code:</p>
  <p>Originator: <code>index.html</code></p>
  <pre><code>&lt;a href=&quot;report/open/123456&quot; target=&quot;_blank&quot;&gt;Open Report&lt;/a&gt;
  </code></pre>
  <p>Intermediary: <code>report.php</code>, this is the function called multiple times for the same request. This is on the same server as <code>index.html</code>, called as a REST request with CodeIgniter handling the routing to the <code>Report</code> controller and invoking the <code>open</code> function.</p>
  <pre><code>&lt;?php
  function open($id) {
      // Here I can detect if Referer is present or not to differentiate first or
      // followup requests, e.g.:
      $headers = getallheaders();
      if (!empty($headers['Referer']))
          echo 'first request';
      else
          echo 'followup request';
      // This is CodeIgniter code to return the contents. If I set a status header
      // of 202 for either the first or followup request instead of doing this, no
      // report is displayed.
      $this-&gt;output-&gt;set_content_type('application/pdf')
          -&gt;set_status_header(200)
          -&gt;set_output(file_get_contents('https://external.com/bigjob/run/'.$id));
  }
  </code></pre>
  <p>Workhorse: <code>bigjob.php</code> on an external server.</p>
  <pre><code>&lt;?php
  function run($id) {
      // heavy PDF file with embedded images returned as raw data stream
  }
  </code></pre>
  <p>The timing seems to be similar to Apache's default Keep-Alive default of 5 seconds, but I don't want to mess with this setting if it's going to affect all the other pages on the originating server.</p>
  <p>As I mentioned, even with the multiple requests, it does seem to work, but it's not very robust or efficient. As well, the external server is heavily loaded at the best of times, so would like to reduce the load on it.</p>
  <p>Has anyone encountered this? If so, is there a solution? I'm okay with using <code>cURL</code> instead of <code>file_get_contents</code> if it means preventing multiple requests, but given the followup request comes from &quot;outside&quot; this function, I have doubts if this approach will work.</p>