title: cURL takes too long to load
body: <p>I am calling a REST endpoint in PHP using cURL to fetch some JSON data:</p>
  
  <pre><code>&lt;?php
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
  $result = curl_exec($ch);
  
  echo $result;
  
  curl_close($ch);
  </code></pre>
  
  <p>It takes 2.5 seconds to fetch the data using the above code on my localhost. The same code takes around 7.5 seconds when run on the live server. When the URL is opened directly on a browser it takes only 1.5 seconds.</p>
  
  <p>My question is: Why does it take so long for cURL to fetch data on the live server and how can I solve this problem?</p>
  
  <p>Below is the output of <code>curl_getinfo($ch)</code> on the server:</p>
  
  <pre><code>Array
  (
      [content_type] =&gt; application/json
      [http_code] =&gt; 200
      [header_size] =&gt; 420
      [request_size] =&gt; 113
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 0
      [redirect_count] =&gt; 0
      [total_time] =&gt; 7.305496
      [namelookup_time] =&gt; 0.150378
      [connect_time] =&gt; 0.473187
      [pretransfer_time] =&gt; 0.473237
      [size_upload] =&gt; 0
      [size_download] =&gt; 1291504
      [speed_download] =&gt; 176785
      [speed_upload] =&gt; 0
      [download_content_length] =&gt; -1
      [upload_content_length] =&gt; 0
      [starttransfer_time] =&gt; 1.787901
      [redirect_time] =&gt; 0
      [redirect_url] =&gt; 
      [certinfo] =&gt; Array
          (
          )
  
      [primary_port] =&gt; 80
      [local_port] =&gt; 53962
  )
  </code></pre>