cURL error 28, 7 and 6 in PHP: timeout, connection refused and could not resolve host

When your site calls an outside service (a payment, an API, an update) and it fails, PHP returns a cURL error number. The three most seen say different things: 6, the address name could not be resolved; 7, the connection was refused; 28, time ran out with no reply. Each has a typical cause and a first test. The message appears in curl_error($ch) and the number in curl_errno($ch). In WordPress it usually shows up in Site Health and in updates as “cURL error 28”.

The three, side by side

Error Message It means First test
6 Could not resolve host PHP could not find out the IP of the address. Is the address spelled right? Open it in a browser.
7 Failed to connect It reached the address, but the connection was refused or never set up. Are the port and protocol right? Is the service up?
28 Operation timed out The connection existed or sat waiting, but the reply did not arrive in time. Is the service slow to answer? Is the time set too short?

Error 6: cannot resolve the name

1 Check the spelling of the address in the code or settings: an extra letter, a space, a doubled https://.
2 Is the destination domain live? If you just registered it or changed its DNS, it may not be visible yet. See how long DNS changes take to propagate.
3 Is it a service of your own, under another name? If the site calls its own domain by an address that only works on your machine (a hosts file, say), the server does not know it.

Error 7: connection refused

1 Check the port. A service listening on 8080 does not answer on 443. See which ports are open.
2 The destination service may be refusing your server’s IP. Many services only accept requests from authorised addresses. See what your hosting IP address is. The outgoing IP may not be the site’s: to be certain, ask us.
3 Is the service down? Check the provider’s status page, or try from your own computer.

Error 28: time ran out

1 Test from the Terminal (if your account has one) with curl -sI https://service.tld/. If it is slow there too, the problem is the service or the path to it.
2 Raise the time, but sensibly. Two options in PHP: CURLOPT_CONNECTTIMEOUT (the time to connect) and CURLOPT_TIMEOUT (the total time). Very short values give false errors; unlimited ones leave your PHP hanging.
3 Do not call the service on every visit. Keep the reply for a while (a simple cache, a WordPress transient) and leave the call to a scheduled job. See running a PHP script from a cron job.
4 Plan for failure. The code should expect the service not to answer and show a decent message instead of hanging the page.
A timeout rather than “refused” suggests something is silently dropping the request, typically a firewall rule at the destination. Refused fast is almost always a wrong port or a stopped service. Timed out is almost always a block or slowness. It is a clue, not a certainty.
Some errors are not your server’s. The code is yours, the service is someone else’s. Our support looks at the server side but does not repair third-party integrations: the boundary is in how far our support goes.

Want to know whether your server can reach an outside address? Send us the address, the port and the full error message.

Open a support ticket

SEE ALSO

Which ports are open, and why your integration hangs without an error

cURL error 60: SSL certificate problem

Where the PHP error log is

What your hosting IP address is and where to find it

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?