title: Variable CURL Response Time
body: <p>I have a PHP CURL request to an HTTPS site which takes a JSON and request and returns a JSON response. Usually it should not take more than 1 second. But, I have seen that the CURL response time is variable. Sometimes, it takes 4 seconds to respond and sometimes 1.2 seconds. Why is this so and How can I make it faster and process the whole request in less than a second?</p>
  
  <p>Following is the curl response times for the same request in 3 different times..</p>
  
  <pre><code>Array
  (
      [url] =&gt; https://xx.xx.xxx.xx/site/y
      [content_type] =&gt; application/json
      [http_code] =&gt; 200
      [header_size] =&gt; 198
      [request_size] =&gt; 358
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 20
      [redirect_count] =&gt; 0
      [total_time] =&gt; 4.213941
      [namelookup_time] =&gt; 2.1E-5
      [connect_time] =&gt; 0.015284
      [pretransfer_time] =&gt; 0.722955
      [size_upload] =&gt; 222
      [size_download] =&gt; 553
      [speed_download] =&gt; 131
      [speed_upload] =&gt; 52
      [download_content_length] =&gt; 0
      [upload_content_length] =&gt; 0
      [starttransfer_time] =&gt; 4.015112
      [redirect_time] =&gt; 0
  )
  
  
  Array
  (
      [url] =&gt; https://xx.xx.xxx.xx/site/y
      [content_type] =&gt; application/json
      [http_code] =&gt; 200
      [header_size] =&gt; 198
      [request_size] =&gt; 358
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 20
      [redirect_count] =&gt; 0
      [total_time] =&gt; 1.27581
      [namelookup_time] =&gt; 8.3E-5
      [connect_time] =&gt; 0.016223
      [pretransfer_time] =&gt; 0.104996
      [size_upload] =&gt; 222
      [size_download] =&gt; 553
      [speed_download] =&gt; 433
      [speed_upload] =&gt; 174
      [download_content_length] =&gt; 0
      [upload_content_length] =&gt; 0
      [starttransfer_time] =&gt; 1.273922
      [redirect_time] =&gt; 0
  )
  
  Array
  (
      [url] =&gt; https://xx.xx.xxx.xx/site/y
      [content_type] =&gt; application/json
      [http_code] =&gt; 200
      [header_size] =&gt; 198
      [request_size] =&gt; 358
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 20
      [redirect_count] =&gt; 0
      [total_time] =&gt; 1.294147
      [namelookup_time] =&gt; 7.0E-5
      [connect_time] =&gt; 0.025723
      [pretransfer_time] =&gt; 0.123456
      [size_upload] =&gt; 222
      [size_download] =&gt; 553
      [speed_download] =&gt; 427
      [speed_upload] =&gt; 171
      [download_content_length] =&gt; 0
      [upload_content_length] =&gt; 0
      [starttransfer_time] =&gt; 1.292577
      [redirect_time] =&gt; 0
  )
  </code></pre>