title: PHP stream_socket_client vs. cURL in TCP SSL
body: <p>I have a problem using <code>cURL</code> to POST XML to a TCP address with SSL. I have to pass an SSL certificate in the request which contains the private key + certficate to verify myself.</p>
  
  <p>I just ran a test with a library using <code>stream_socket_client()</code> and it uses the <code>stream_context_set_option</code> to add an option <code>local_cert</code> in which it passes the certificate. Now I can get myself verified using this method, but I cannot do it in cURL. All I get is a <code>connection reset by peer</code> error which means the certificate verification failed. What's the difference? Do I have to abandon cURL because it would be (in my opinion) a much cleaner solution.</p>
  
  <p><code>$content</code> is valid XML.</p>
  
  <pre><code>    $headers = [
          "Content-type: text/xml",
          "Content-length: " . strlen($content),
          "Connection: close",
      ];
  
      $curl = curl_init();
  
      curl_setopt($curl, CURLOPT_URL, 'epptest.ficora.fi');
      curl_setopt($curl, CURLOPT_PORT, 700);
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
      curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($curl, CURLOPT_SSLCERT, __DIR__ . '/certificate.pem');
      curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
  
      $output = curl_exec($curl);
  
      echo 'Error ' . curl_errno($curl) . ': "' . curl_error($curl) .'"';
  
      var_dump($output);
  </code></pre>
  
  <p>cURL verbose:</p>
  
  <pre><code> * Rebuilt URL to: epptest.ficora.fi/
  * Hostname in DNS cache was stale, zapped
  *   Trying 87.239.122.59...
  * Connected to epptest.ficora.fi (87.239.122.59) port 700 (#0)
  &gt; POST / HTTP/1.1
  Host: epptest.ficora.fi:700
  Accept: */*
  Content-type: text/xml
  Content-length: 406
  Connection: close
  
  * upload completely sent off: 406 out of 406 bytes
  * Recv failure: Connection was reset
  * Closing connection 0
  </code></pre>