title: CURL, cPanel and 'curl_exec threw error "couldn't connect to host"'
body: <p>So I'm trying to use cPanel API(XML) to log into the interface and run a full backup, </p>
  
  <p>However I get the same error stack all the time </p>
  
  <pre><code>&gt; Fatal error:  Uncaught exception 'Exception' with message 'curl_exec threw error "couldn't connect to host" for
  &gt; https://37.111.11.1:2083/xml-api/cpanel?&lt;all of the vars&gt;' in
  &gt; /home/liamb/public_html/whmcs/backup_class.php:839 Stack trace:
  &gt; #0 /home/liamb/public_html/whmcs/backup_class.php(763): xmlapi-&gt;curl_query('https://37.26.1...', 'cpanel_xmlapi_u...',
  &gt; 'Authorization: ...')
  &gt; #1 /home/liamb/public_html/whmcs/backup_class.php(938): xmlapi-&gt;xmlapi_query('cpanel', Array)
  &gt; #2 /home/liamb/public_html/whmcs/backup_class.php(83): xmlapi-&gt;api1_query('a123', 'Fileman', 'fullbackup', Array)
  &gt; #3 /home/liamb/public_html/whmcs/backup.php(32): backup-&gt;add_cPanel()
  &gt; #4 {main}   thrown in /home/liamb/public_html/whmcs/backup_class.php on line 839
  </code></pre>
  
  <p>I can't figure out why this is, I can access it through browser however it's forcing SSL, CURL is set to handle the unverified certificate, but I think this is where it breaks, here's the CURL code</p>
  
  <pre><code>$curl = curl_init();
  
      // Set the URL
      curl_setopt($curl, CURLOPT_URL, $url);
      // Increase buffer size to avoid "funny output" exception
      curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072);
      curl_setopt( $curl , CURLOPT_SSL_VERIFYHOST , 0 ); 
      curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER , 0 );
      curl_setopt( $curl, CURLOPT_RETURNTRANSFER , 1 );
  
      // Pass authentication header
      $header[0] =$authstr .
          "Content-Type: application/x-www-form-urlencoded\r\n" .
          "Content-Length: " . strlen($postdata) . "\r\n" . "\r\n" . $postdata;
  
      curl_setopt( $curl, CURLOPT_HTTPHEADER , $header );
  
      $result = curl_exec($curl);
      echo "&lt;pre&gt;".print_r(curl_getinfo($curl),1)."&lt;/pre&gt;";
      if ($result == false) {
          throw new Exception("curl_exec threw error \"" . curl_error($curl) . "\" for " . $url . "?" . $postdata );
      }
      curl_close($curl);
      return $result;
  </code></pre>
  
  <p>CURL info produces the following </p>
  
  <pre><code>  Array
  (
      [url] =&gt; https://37.111.11.1:2083/xml-api/cpanel
      [content_type] =&gt; 
      [http_code] =&gt; 0
      [header_size] =&gt; 0
      [request_size] =&gt; 0
      [filetime] =&gt; -1
      [ssl_verify_result] =&gt; 0
      [redirect_count] =&gt; 0
      [total_time] =&gt; 189.000809
      [namelookup_time] =&gt; 0.000163
      [connect_time] =&gt; 0
      [pretransfer_time] =&gt; 0
      [size_upload] =&gt; 0
      [size_download] =&gt; 0
      [speed_download] =&gt; 0
      [speed_upload] =&gt; 0
      [download_content_length] =&gt; -1
      [upload_content_length] =&gt; -1
      [starttransfer_time] =&gt; 0
      [redirect_time] =&gt; 0
      [certinfo] =&gt; Array
          (
          )
  
      [redirect_url] =&gt; 
  )
  </code></pre>
  
  <p>Anyone could help? Been stuck on this for days! </p>
  
  <p>Update: If I try to connect to 127.0.0.1 it works! Well at least it brings back the XML output! </p>