Curl request is failing on the SSL?

Curl request is failing on the SSL?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Curl request is failing on the SSL?

You are encountering curl_error outputting SSL read: error:00000000:lib(0):func(0):reason(0) alongside an errno of 104. This specific combination points to a fundamental misalignment between your OpenSSL configuration and the remote server's certificate chain. The code snippet provided attempts to disable peer verification for HTTP URLs, but the error persists because the root cause isn't simply about enabling CURLOPT_SSL_VERIFYPEER.

The error code errno 104 corresponds to ECONNRESET (Connection reset by peer). In the context of SSL/TLS handshakes, this indicates that the connection was abruptly terminated before the handshake could complete. This usually happens when the server closes the socket immediately after sending the Server Hello or during the certificate verification phase.

Your current logic checks if the URL starts with http to decide whether to verify peers:

if(ereg("^(https)",$url))
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);

There are three critical issues here that contribute to this failure. First, the regex pattern is incorrect. The operator ereg checks if the string matches the pattern. If $url is https://example.com, the pattern ^(https) does not match because the URL contains more characters than just "https". You would need ^https://. However, even fixing the regex doesn't solve the underlying protocol mismatch causing the connection reset.

Secondly, disabling CURLOPT_SSL_VERIFYPEER is a band-aid solution that ignores the actual error signature. The SSL_read: ... lib(0):func(0) error often stems from an OpenSSL version incompatibility or a specific cipher suite negotiation failure. If the server sends a certificate that your local OpenSSL library cannot parse or verify due to algorithm restrictions (like SHA-1 deprecation) or missing CA certificates, the handshake fails immediately.

The most robust solution involves ensuring the client has access to a valid root certificate bundle. On Linux systems, this typically means checking if ca-certificates are installed and accessible at the default path used by Curl (/etc/ssl/certs/ca-certificates.crt). If the server presents a certificate signed by a private or self-signed CA that is not in your trust store, the handshake will fail with a connection reset rather than a standard "certificate verification failed" error if CURLOPT_CAINFO is not configured correctly.

If you must connect to an internal server using a self-signed certificate and cannot modify the server configuration, passing the specific certificate file to Curl is safer than disabling verification globally:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_CAINFO, '/path/to/server.crt');

This approach maintains security by verifying the peer against a known good source rather than skipping validation entirely. If you are running this within a Laravel application, ensure your environment variables for SSL paths are correctly set, especially if you are using php-curl on a shared hosting environment or a containerized setup where /etc/ssl/certs might be empty.

Finally, consider the OpenSSL version. Older versions of OpenSSL (prior to 1.0.1) have known issues with SNI (Server Name Indication) and specific TLS versions that can trigger ECONNRESET. If you cannot upgrade the PHP binary immediately, you might need to explicitly set the SSL protocol version:

curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);

This forces a modern handshake method that is less prone to version-specific negotiation errors. Always prioritize fixing the certificate chain or upgrading libraries over disabling security checks, as errno 104 is a symptom of a deeper handshake failure that disabling verification masks but does not resolve.

Our network