Ad Space — Top Banner

CURL error

PHP Programming Language

Severity: Moderate

What Does This Error Mean?

A PHP cURL error means your script tried to make an HTTP request to a URL and something went wrong. cURL is the PHP library for making web requests — fetching API data, downloading files, or posting forms to external services. Errors range from 'could not resolve host' (bad URL or DNS issue) to SSL certificate failures to connection timeouts. The error number tells you exactly what went wrong.

Affected Models

  • PHP 5.x
  • PHP 7.x
  • PHP 8.x
  • All PHP versions with cURL extension

Common Causes

  • The URL is wrong or the domain does not exist (error 6: could not resolve host)
  • The remote server is down or refusing connections (error 7: failed to connect)
  • The request timed out because the server was too slow to respond (error 28: operation timed out)
  • An SSL certificate error — the certificate is expired, self-signed, or the hostname does not match (error 60)
  • The cURL extension is not enabled on the server

How to Fix It

  1. Always check for cURL errors after executing a request: if (curl_errno($ch)) { echo curl_error($ch); }

    curl_errno() returns the error number (0 means no error). curl_error() returns a readable description.

  2. For error 6 (could not resolve host), double-check the URL. Make sure the domain is spelled correctly and exists.

    Test by pasting the URL into a browser. If it does not load there either, the URL or server is the problem.

  3. For error 28 (timeout), increase the timeout: curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    The default timeout is very short. For slow external APIs, set a longer timeout of 15–30 seconds.

  4. For SSL errors (error 60), make sure your server has an up-to-date CA certificate bundle. Do NOT disable SSL verification in production.

    Setting CURLOPT_SSL_VERIFYPEER to false bypasses certificate checking. This is a serious security risk. Fix the certificate instead.

  5. Run phpinfo() and search for 'curl' to confirm the cURL extension is enabled. If not, enable it in php.ini with: extension=curl

    On shared hosting, contact your provider if you cannot enable extensions yourself.

When to Call a Professional

cURL errors related to SSL certificates or network configuration on a production server may need a sysadmin. For API integration issues, the API provider's developer support is often the right contact. For cURL errors inside a framework or library, report them with the full error output.

Frequently Asked Questions

What are the most common cURL error codes?

Error 6: Could not resolve host — the domain does not exist or DNS failed. Error 7: Failed to connect — the server refused or is unreachable. Error 28: Operation timed out — the server did not respond in time. Error 35: SSL connect error — the SSL handshake failed. Error 60: SSL certificate problem — certificate is invalid or untrusted.

Is it okay to disable SSL verification to fix cURL error 60?

Only on a local development server, never on a live site. Disabling SSL verification means your script no longer checks that the server is who it claims to be. This opens the door to man-in-the-middle attacks. Fix the SSL certificate issue instead.

How do I see the full HTTP response even when there is an error?

Set CURLOPT_RETURNTRANSFER to true so cURL returns the response body as a string. Then check curl_getinfo($ch, CURLINFO_HTTP_CODE) to see the HTTP status code. A 200 means success. A 4xx or 5xx means the server returned an error, which is different from a cURL network error.