title: PHP low performance on cURL and file_get_contents
body: <p>I'm developing a PHP script which request some data from a REST API.</p>
  
  <p>First i was using cURL for PHP, however it took too much time to send the request and get the response. Then i tried to use file_get_contents, but i got same results. </p>
  
  <p>I say that PHP takes too much time (15 s) because, i consulted the same URL in the browser (chrome), in the same PC, and it took only 68ms.</p>
  
  <p>I thought that it could be the environment, but my pc's spec is: Core i5-4570, 8GB RAM, W7x64, all updates, PHP 5.6.8 x32, Chrome v42 x64 with a lot of complements.  I'm running php on the embedded server. </p>
  
  <p>I even tried to replace the server name in the URL for the IP server (avoid DNS look) but got the same results. </p>
  
  <p>I set set_time_limit(3600) (php script time out), but i don't want the script to take so long to exec. </p>
  
  <p>Any help please?</p>
  
  <p><strong>EDIT:</strong>
  My code is:
  PHP - cURL Time to exec (17.66 s)</p>
  
  <pre><code>$headers = array(
  'Content-type: application/json',
  'Authorization: Basic '.base64_encode($usr.':'.$pwd)
  );
  
  $opt = array(
      CURLOPT_HTTPHEADER =&gt; $headers,
      CURLOPT_URL =&gt; "http://url.example.com"
  );
  $ch = curl_init();
  curl_setopt_array($ch, $opt );
  curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p>file_get_contents (13.63 s)</p>
  
  <pre><code>$headers = ['http' =&gt; ['header' =&gt; 'Authorization: Basic'.base64_encode($usr.':'.$pwd)] ];
  $context = stream_context_create($headers);
  file_get_contents("http://url.example.com", false, $context);
  </code></pre>
  
  <p>cURL command Line time to exec (12 s)</p>
  
  <pre><code> curl -D- -u "user:pwd" -X GET -H "Content-Type: application/json" http://url.example.com -o out.json -v
  </code></pre>
  
  <p>Browser (45 - 63 ms)</p>
  
  <p>I don't think the download size matters since it's about 1.2 KB.</p>
  
  <p>I tried using gzip compression in cURL PHP but the output is encoded and don't know how to decode it. I'm really considering to use ASP.net and see the performance results.</p>
  
  <p>Any configuration in PHP ini could help? like increasing the buffer size, default memory assigned?</p>