title: PHP curl Unknown SSL protocol error
body: <p>We've recently moved our web application to a new server and curl requests through PHP have stopped working for HTTPS addresses (HTTP still works fine).</p>
  
  <p>The old server was running openSUSE 12.3 and the new server is Ubuntu 16.04.</p>
  
  <p>I've tried <code>curl_setopt( $ch, CURLOPT_SSLVERSION, 1 );</code> to force TLS as suggested in answers to similar questions here, but it makes no difference.</p>
  
  <p>It's all the more confusing because an HTTPS request to the same location using curl at the command line works exactly as I'd expect.</p>
  
  <p>I turned on verbose output in the PHP curl call to see if that would help me and got the following output:</p>
  
  <pre><code>*   Trying xxx.xxx.xxx.xxx...
  * Connected to www.somesite.com (xxx.xxx.xxx.xxx) port 443 (#0)
  * ALPN, offering http/1.1
  * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
  * successfully set certificate verify locations:
  *   CAfile: /etc/ssl/certs/ca-certificates.crt
    CApath: /etc/ssl/certs
  * Unknown SSL protocol error in connection to www.somesite.com:443
  * Closing connection 0
  </code></pre>
  
  <p>but when I run the command at the command line (using something like <code>curl -d "My=post&amp;data=here" -X POST https://www.somesite.com/... -v</code>) I get:</p>
  
  <pre><code>*   Trying xxx.xxx.xxx.xxx...
  * Connected to www.somesite.com (xxx.xxx.xxx.xxx) port 443 (#0)
  * found 173 certificates in /etc/ssl/certs/ca-certificates.crt
  * found 696 certificates in /etc/ssl/certs
  * ALPN, offering http/1.1
  * SSL connection using TLS1.0 / RSA_3DES_EDE_CBC_SHA1
  *        server certificate verification OK
  *        server certificate status verification SKIPPED
  *        common name: *.somesite.com (matched)
  *        server certificate expiration date OK
  *        server certificate activation date OK
  *        certificate public key: RSA
  *        certificate version: #3
  *        subject: C=****,ST=****,L=****,O=****,OU=****,CN=*.somesite.com
  *        start date: Fri, 27 Jan 2017 00:00:00 GMT
  *        expire date: Wed, 26 Feb 2020 23:59:59 GMT
  *        issuer: C=US,O=thawte\, Inc.,CN=thawte SSL CA - G2
  *        compression: NULL
  * ALPN, server did not agree to a protocol
  ...Response here...
  </code></pre>
  
  <p>Does anyone have any suggestions as to how to fix this, or what I can do to narrow down the cause of the issue?</p>
  
  <p>UPDATE:</p>
  
  <p>Here is the PHP code I'm using to try and find the cause of the problem:</p>
  
  <pre><code>$postvars="My=post&amp;data=here";
  
  $curl=curl_init(
          "https://www.somesite.com/..."
      );
  curl_setopt($curl, CURLOPT_VERBOSE, true);
  curl_setopt($curl, CURLOPT_STDERR, fopen('/tmp/sslerror', 'w'));
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  $result=curl_exec($curl);
  echo curl_error($curl);
  curl_close($curl);
  echo var_export($result, true);
  </code></pre>