title: Get file contents when Connection is keep-alive
body: <p>I need to get the contents of a remote file, but with sending a few headers, and one of them is the "Connection: keep-alive" header... so I tried it with a simple call to file_get_contents(), like this: </p>
  
  <pre><code>&lt;?php
  
  $sfheaders="Cache-Control:max-age=0
  Connection:keep-alive";
  
  $opts = array(
      'http' =&gt; array(
          'method' =&gt; "GET",
          'header' =&gt; $sfheaders
      )
  );
  
  $context = stream_context_create($opts);
  
  $url="http://somedomain.com/to.php";
  $file = file_get_contents($url, false, $context);
  ?&gt;
  </code></pre>
  
  <p>... the code works, but it takes 15 seconds for file_get_contents to get the data! It looks like file_get_contents() finishes after the connection closes, but I want it to finish after the data is transferred. It is faster if I remove the keep-alive header but this time I need to get the data while the connection is kept alive.  I guess that is not possible with file_get_contents, so ....</p>
  
  <p>is there a way to do it with cURL or with something else?</p>
  
  <p>Edit: Let me be more accurate, the "Connection:keep-alive" header must be send to the specific server I am trying to access because it checks for that header, and if it is not send, then there is no data send to me! Got it?</p>