title: Why CodeIgniter's Curl library slower than using Curl in plain PHP?
body: <p>Recently I moved my scraping code with Curl to CodeIgniter. I'm using Curl CI library from <a href="http://philsturgeon.co.uk/code/codeigniter-curl" rel="nofollow">http://philsturgeon.co.uk/code/codeigniter-curl</a>. I put the scraping process in a controller and then I found the execution time of my scraping is slower than the one I built in plain PHP.</p>
  
  <p>It took 12 seconds for CodeIgniter to output the result, whereas it only takes 6 seconds in plain PHP. Both are including the parsing process with the HTML DOM parser.</p>
  
  <p>Here's my Curl code in CodeIgniter:</p>
  
  <pre><code>function curl($url, $postdata=false)
  {
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
  
    $this-&gt;curl-&gt;create($url);
    $this-&gt;curl-&gt;ssl(false);
    $options = array(
      'URL'             =&gt; $url,
      'HEADER'          =&gt; 0,
      'AUTOREFERER'     =&gt; true,
      'FOLLOWLOCATION'  =&gt; true,
      'TIMEOUT'         =&gt; 60,
      'RETURNTRANSFER'  =&gt; 1,
      'USERAGENT'       =&gt; $agent,
      'COOKIEJAR'       =&gt; dirname(__FILE__) . "/cookie.txt",
      'COOKIEFILE'      =&gt; dirname(__FILE__) . "/cookie.txt",
    );
  
    if($postdata)
    {
      $this-&gt;curl-&gt;post($postdata, $options);
    }
    else
    {
      $this-&gt;curl-&gt;options($options);
    }
  
    return $this-&gt;curl-&gt;execute();
  }
  </code></pre>
  
  <p>non codeigniter (plain php) code :</p>
  
  <p>function curl($url ,$binary=false,$post=false,$cookie =false ){</p>
  
  <pre><code>    $ch = curl_init();
  
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
      curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 2); 
  
      curl_setopt ($ch, CURLOPT_URL, $url );
      curl_setopt ($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_REFERER, $url);
      curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
      curl_setopt($ch, CURLOPT_AUTOREFERER, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_TIMEOUT, 60);
      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  
  
  
      if($cookie){
  
  
          $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
          curl_setopt($ch, CURLOPT_USERAGENT, $agent);
          curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookie.txt");
          curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
  
      }
  
  
      if($binary)
          curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  
  
      if($post){
  
  
          foreach($post as $key=&gt;$value) 
              { 
          $post_array_string1 .= $key.'='.$value.'&amp;'; 
          }
          $post_array_string1 = rtrim($post_array_string1,'&amp;');
  
          //set the url, number of POST vars, POST data
  
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array_string1);
      }
  
          return  curl_exec ($ch);
  </code></pre>
  
  <p>}</p>
  
  <p>Does anyone know why this CodeIgniter Curl is slower??  or maybe it's because the simple_html_dom parser??</p>