SSL error "unexpected eof while reading" on same server as the originating request

SSL error "unexpected eof while reading" on same server as the originating request

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

Stefan Bogdanescu

Founder & Senior Architect

SSL error "unexpected eof while reading" on same server as the originating request

You are encountering the SSL Library Error: error:0A000126:SSL routines::unexpected eof while reading because you have inadvertently triggered a defensive mechanism introduced in OpenSSL 3. This behavior isn't necessarily a bug in your PHP or curl configuration; rather, it is a result of stricter truncation attack protections that were reintroduced in the library.

When making an HTTP request from a local server to itself using curl within PHP, you might logically assume that since both ends are running identical software, compatibility issues should not arise. However, SSL/TLS handshakes are strictly protocol-based. If the client and server negotiate different parameters during the handshake phase, the connection can be severed prematurely. In this specific scenario, OpenSSL 3 detects a mismatch in the negotiated TLS version or cipher suite between your PHP process acting as the client and your web server acting as the target.

The error occurs because the client (your PHP script) attempts to initiate a connection with parameters that the server rejects or handles differently than expected, causing the server to close the stream before sending any data back. OpenSSL 3 interprets this abrupt closure as an attempt to truncate the stream—a potential attack vector—and raises the "unexpected eof" error to prevent it.

To resolve this, you must explicitly align the client's negotiation parameters with the server's capabilities. Your httpd.conf currently allows TLSv1.2 and TLSv1.3, but your PHP curl call relies on default behavior. In OpenSSL 3, the defaults for cipher suites and protocols have shifted significantly compared to previous versions. When you set CURLOPT_SSL_CIPHER_LIST to NULL, you are relying on the client's default suite, which may not match the server's configured list exactly, or the server may reject the connection before sending a proper response if the client proposes an unsupported cipher order.

The most direct fix is to explicitly specify the TLS version and a compatible cipher in your PHP request. Instead of relying on defaults, you should configure CURLOPT_SSLVERSION and CURLOPT_SSL_CIPHER_LIST. For instance, forcing TLSv1.2 or TLSv1.3 ensures that both ends agree on the protocol version before any data is exchanged.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:80/endpoint'); // Ensure target is http if using SSL certs on 80, or https appropriately
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_HEADER, false);

// Explicitly set the TLS version to match server capabilities
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); 

// Define a specific cipher list compatible with your SSLHonorCipherOrder settings
// Ensure this matches what is allowed in your httpd.conf
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256');

// Proceed with other necessary options like SSL_VERIFYPEER
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/ca-certs.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

$response = curl_exec($ch);
if ($response === false) {
    $error = curl_error($ch);
    $errno = curl_errno($ch);
}

By hardcoding these values, you eliminate the ambiguity of default negotiation. You are essentially telling the client: "I will only speak TLSv1.2 using these specific ciphers." If your server is configured to accept these, the handshake completes successfully, and OpenSSL 3 no longer raises a truncation error because the data stream flows as expected.

While upgrading PHP to version 8.1 or later might eventually provide better defaults for OpenSSL 3 compatibility, that path is blocked by library dependencies on your system. Until then, explicit configuration is the reliable workaround. Ensure that the cipher list you specify in PHP exactly mirrors the order and content defined in your Apache SSLCipherSuite directive. Mismatches here are common causes of handshake failures in heterogeneous environments, even when running locally.

Our network