title: PHP curl through proxy generating high CPU load
body: <p>After investigating the reasons for the high CPU load generated by an application sending many curl requests with 20 parallel PHP-cli scripts, I've found out the main reason is the PROXY option set to the curl handle.</p>
  
  <p>The following code is generating a 0.5-1.5% CPU load at the moment of curl_exec when run without the proxy and 12-25% when using any proxy (I've tried many different ones).</p>
  
  <p>With many threads running many requests at the same time, it soon becomes critical.</p>
  
  <p>I'm using:
  Ubuntu 16.04
  PHP 7.0.22
  curl 7.55.1</p>
  
  <p>Is there a fix or workaround I can apply?</p>
  
  <pre><code>$address = 'xxx';
  $port = 'xxx';
  $url = 'https://api.ipify.org?format=json';
  
  do {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_ENCODING, 'identity');
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($ch, CURLOPT_PROXY, $address);
      curl_setopt($ch, CURLOPT_PROXYPORT, $port);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_exec($ch);
      curl_close($ch);
      sleep(10);
  
  } while (true); 
  </code></pre>