title: PHP Curl Slowness
body: <p>For some reason my curl call is very slow. Here is the code I used.</p>
  
  <pre><code>$postData = "test"
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HEADER, false);
  $result = curl_exec($ch);
  </code></pre>
  
  <p>Executing this code takes on average 250ms to finish.
  However when I just open the url in a browser, firebug says it only takes about 80ms.</p>
  
  <p>Is there something I am doing wrong? Or is this the overhead associated with PHP Curl.</p>
  
  <p>It's the call to</p>
  
  <pre><code>curl_exec
  </code></pre>
  
  <p>That is taking up all the time.</p>
  
  <p>UPDATE:</p>
  
  <p>So I figured out right after I posted this that if I set the curl option</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  </code></pre>
  
  <p>It significantly slows down</p>
  
  <pre><code>curl_exec
  </code></pre>
  
  <p>The post data could be anything and it will slow it down.</p>
  
  <p>Even if I set</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_POST, false);
  </code></pre>
  
  <p>It's slow.</p>
  
  <p>I'll try to work around it by just adding the parameters to the URI as a query string.</p>
  
  <p>SECOND UPDATE:</p>
  
  <p>Confirmed that if I just call the URI using GET and passing parameters
  as a query string it is much faster than using POST and putting the parameters in the body.</p>