Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kratos-digital's avatar

Http::get cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0

I am fetching all countries from this API: $response = Http::get('https:// restcountries.com/v3.1/all'); (and it worked fine several days ago). I did not update Laravel or any other package, and it stopped working with error: "cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0".

Using postman, curl via terminal or even browser - API works.

I tried searching this forum - no working solutions, I tried google - same, I tried chat gpt - anything suggested throws same error. Same error in local env and on real server in production env.

When I try other API like "/v3.1/capital/tallinn" it works. I guess the content size from API increased in past several days and the problem is with the content length, which guzzle inside Http wrapper can't handle. But can't find the fix.

I tried using stream, custom headers, sink (it breaks at Sri Lanka), increase timeout, connection timeout, any possible solution or workaround I found - same error.

This is debug output:

* Host restcountries.com:443 was resolved. * IPv6: (none) * IPv4: 146.190.198.121 * Trying 146.190.198.121:443... * ALPN: curl offers http/1.1 * CAfile: /Users/kikky/Library/Application Support/Herd/config/php/cacert.pem * CApath: none * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / x25519 / id-ecPublicKey * ALPN: server accepted http/1.1 * Server certificate: * subject: CN=restcountries.com * start date: Oct 25 14:44:04 2024 GMT * expire date: Jan 23 14:44:03 2025 GMT * subjectAltName: host "restcountries.com" matched cert's "restcountries.com" * issuer: C=US; O=Let's Encrypt; CN=E6 * SSL certificate verify ok. * Certificate level 0: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA384 * Certificate level 1: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using sha256WithRSAEncryption * Certificate level 2: Public key type RSA (4096/152 Bits/secBits), signed using sha256WithRSAEncryption * Connected to restcountries.com (146.190.198.121) port 443 * using HTTP/1.x > GET /v3.1/all HTTP/1.1 Host: restcountries.com User-Agent: GuzzleHttp/7 * Request completely sent off < HTTP/1.1 200 OK < Server: nginx/1.22.1 < Date: Sun, 08 Dec 2024 19:50:22 GMT < Content-Type: application/json < Content-Length: 833487 < Connection: keep-alive < Cache-Control: public, immutable, max-age=31556926 < * OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 0 * closing connection #0

Anyone has working solution?

3 likes
6 replies
vincent15000's avatar

Does the API need any kind of key which would have been regenerated ?

kratos-digital's avatar

No keys required, you can simply visit the API URL as-is using postman, browser or terminal curl.

1 like
kratos-digital's avatar

@vincent15000 I know, and your reply shows me you didn't read the issue at all.

I clearly said https:// restcountries.com/v3.1/all fails, while others (that return smaller response body) such as /v3.1/capital/tallinn (and your example) don't fail.

1 like
kratos-digital's avatar
kratos-digital
OP
Best Answer
Level 1

Fixed it with custom header. Using php curl it also didn't pass, so I tried with postman and took this header from postman. Content length for this route is over 800 kb and such content size just fails using php curl. Of course, any AI was useless in resolving the issue.

$response = Http::withHeaders([ 'Accept-Encoding' => 'gzip, deflate, br', ])->get('https://restcountries.com/v3.1/all');

2 likes

Please or to participate in this conversation.