title: Make HTTP/1.1 request with PHP
body: <p>My code is using <code>file_get_contents()</code> to make GET requests to an API endpoint. It looks like it is using <code>HTTP/1.0</code> and my sysadmin says I need to use <code>HTTP/1.1</code>. How can I make an <code>HTTP/1.1</code> request? Do I need to use curl or is there a better/easier way?</p>
  <h3>Update</h3>
  <p>I decided to use cURL since I am using PHP 5.1.6. I ended up forcing HTTP/1.1 by doing this:</p>
  <pre><code>curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  </code></pre>
  <p>If I was using 5.3 or later I would have tried doing something like this:</p>
  <pre><code>$ctx = stream_context_create(array(
      'http' =&gt; array('timeout' =&gt; 5, 'protocol_version' =&gt; 1.1)
      ));
  $res = file_get_contents($url, 0, $ctx);
  echo $res;
  </code></pre>
  <p><a href="http://us.php.net/manual/en/context.http.php" rel="nofollow noreferrer">http://us.php.net/manual/en/context.http.php</a></p>
  <blockquote>
  <p>Note: PHP prior to 5.3.0 does not
  implement chunked transfer decoding.
  If this value is set to 1.1 it is your
  responsibility to be 1.1 compliant.</p>
  </blockquote>
  <p>Another option I found which might provide HTTP/1.1 is to use the <a href="http://php.net/manual/en/book.http.php" rel="nofollow noreferrer">HTTP extension</a></p>