CURL - Error code: 6 Couldn't resolve host 'http://www.yahoo.com' - XAMPP

CURL - Error code: 6 Couldn't resolve host 'http://www.yahoo.com' - XAMPP

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

Stefan Bogdanescu

Founder & Senior Architect

CURL - Error code: 6 Couldn't resolve host 'http://www.yahoo.com' - XAMPP

When you encounter Error code: 6 from cURL, the immediate error message "Couldn't resolve host" indicates a DNS failure, not a network connectivity issue or a server-side rejection. In your specific case on XAMPP, the script is attempting to fetch http://www.yahoo.com, but the underlying operating system cannot map that domain name to an IP address. This distinction is critical because it shifts the debugging focus from PHP configuration to system-level networking.

The code snippet you provided initializes a handle, sets a connection timeout of 60 seconds, and executes the request. If $result is empty or false, you correctly check curl_errno and curl_error. However, these functions only report what cURL received back; they do not diagnose why the initial DNS lookup failed. The error code 6 specifically means the resolver returned an empty string for the hostname.

This usually happens on local development environments like XAMPP because the PHP process runs without access to the standard system DNS resolver, or because that resolver is misconfigured. On Windows-based XAMPP installations, this is often due to missing or incorrect entries in the hosts file (C:\Windows\System32\drivers\etc\hosts) or a broken connection to external DNS servers like Google (8.8.8.8) or Cloudflare (1.1.1.1).

To verify if your system can resolve the domain independently of PHP, open a Command Prompt and run:

ping www.yahoo.com
nslookup www.yahoo.com

If these commands fail with "DNS_PROBE_FINISHED_NXDOMAIN" or similar errors, the issue is strictly at the OS level. You must fix your DNS settings before cURL will succeed. Ensure that your hosts file does not contain a conflicting entry for www.yahoo.com, and verify that your network adapter is configured to use valid DNS servers.

Even if your internet works in the browser, PHP might be isolated by firewall rules or sandboxing features depending on how XAMPP is installed. Some security configurations prevent PHP from performing outbound raw socket connections required for cURL. Check your php.ini file for directives like allow_url_fopen and ensure that extensions like curl are loaded correctly. Run:

php -m | findstr curl

If the extension is missing, you need to enable it by uncommenting extension=curl in php.ini. Without this module, cURL functions will throw fatal errors rather than DNS errors, but since you are seeing code 6, the module is likely loaded; the problem remains the resolver.

Another common pitfall involves URL construction. Your code uses $sendurl = "http://www.yahoo.com";. While this works in many contexts, some strict environments or specific cURL configurations might struggle if the URL contains whitespace or special characters not properly escaped. However, www.yahoo.com is a standard domain, so this is unlikely the cause unless the variable was inadvertently overwritten before execution.

Consider also that XAMPP sometimes runs Apache with restrictions that affect PHP's ability to access the network directly. If you are running a virtual machine or a containerized version of XAMPP, ensure that port 53 (DNS) and standard HTTP ports are not blocked by host firewall software.

Once your DNS resolution is working at the OS level, re-run your PHP script. The error should disappear, and curl_exec will return the HTML content of the page. If you are migrating this logic to a production environment outside of XAMPP, remember that local development quirks often do not translate directly to Linux servers where the system resolver is typically more robust.

For developers building scalable applications on top of cURL, always wrap DNS failures in specific exception handling logic so that your application doesn't silently fail or timeout indefinitely. Treat a "couldn't resolve host" error as an immediate infrastructure alert rather than a transient network glitch.

Our network