OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
When curl_exec returns OpenSSL SSL_read: SSL_ERROR_SYSCALL accompanied by errno 104 (ECONNRESET), the immediate assumption is often a cryptographic failure. Developers frequently jump to checking certificate validity or signature algorithms. However, this specific error combination almost always indicates a network-level interruption rather than a handshake failure. The underlying read operation failed because the remote server abruptly closed the connection or the local system lost its TCP socket, leaving OpenSSL with nothing to read.
In your specific scenario, you are attempting to send an HMAC-SHA1 signature and JSON payload to https://www.compu-cover.com. The code sets CURLOPT_SSL_VERIFYPEER to true, which is correct for production environments. This option ensures the server's certificate chain is verified against a trusted root store. If the server presents a valid certificate, this flag will not trigger an error unless the network connection drops mid-stream.
The primary suspect when encountering ECONNRESET on an HTTPS request is how the target server handles the response or the request itself. A common pitfall in API integrations is sending malformed payloads that cause the server to terminate the connection immediately. If your JSON structure contains unexpected characters, exceeds size limits, or triggers a security filter (like a WAF) on the receiving end, the server may send an RST packet instead of an HTTP response body. OpenSSL interprets this abrupt closure as a system call error during its read buffer fill.
Another frequent cause is certificate transparency issues. Even if CURLOPT_SSL_VERIFYPEER is enabled, if your local environment lacks the root Certificate Authority (CA) required to verify the server's chain, the handshake might fail in ways that manifest as read errors depending on the OpenSSL version and configuration. You should ensure your system has up-to-date CA certificates installed. On Debian/Ubuntu systems, this usually means ensuring the ca-certificates package is current.
Consider the possibility of a firewall or security group rule intervening. If an intermediate proxy or load balancer sits between your client and the target server, it might be terminating SSL connections prematurely. This often happens when keep-alive headers are missing or mismatched. Ensure that your curl session does not reuse sockets in a way that conflicts with the server's expectations. You can test this by forcing a fresh connection:
curl --max-time 5 --connect-timeout 5 \
-v https://www.compu-cover.com/intelligent-rewards/orders/?OrderNo=123
The verbose flag (-v) is critical here. It will show you the SSL handshake details and whether the connection was reset after the headers were sent but before the body was received. Look specifically for Connection: close headers or any reset messages in the output.
There is also the matter of HTTP protocol mismatches. If the server expects HTTP/1.1 with specific keep-alive behavior but receives an incomplete request, it will reset the connection. Your current code uses json_encode without specifying a content type. While modern servers often infer application/json, explicitly setting the header ensures compatibility:
curl_setopt($session, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
Finally, verify the signature calculation logic. If the server rejects the request with a 403 Forbidden status and immediately closes the socket without sending a proper HTTP response header, curl might misinterpret this as a read error depending on how the buffer was handled. Ensure that the double HMAC implementation matches the server's expectation exactly, including line endings if the signature is appended to the body rather than being a separate header.
If these checks do not resolve the issue, consult the server-side logs if you have access to them. The remote endpoint might be logging connection resets due to payload size or specific header violations that are silent on the client side. For production-grade HTTP clients in PHP, consider reviewing resources like https://laravelcompany.com for insights into robust SSL configuration patterns that handle edge cases involving server-side resets more gracefully.
