cURL / Mailing Lists / curl-and-php / Single Mail


cURL can't resolve host through Apache/PHP, works with PHP/CLI

From: Philip Espersen <>
Date: Thu, 6 Sep 2007 23:41:59 +0200

Hi List,

I'm running my own webserver with FreeBSD 6.1, Apache 2.2.4, PHP 5.2.3 and
cURL, here's info about cURL saxet from phpinfo().

libcurl/7.16.3 OpenSSL/0.9.7e zlib/1.2.2 c-ares/1.4.0 libidn/0.6.14

When i try to use cURL from PHP throug a website i get a error 6 Can't
resolve host.

I have made this little test script that i use.

echo 'gethostbyaddr:' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . '<br>;
echo 'gethostbyname:' . gethostbyname('') . '<br>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_HEADER, 0);
echo curl_errno($ch) . curl_error($ch);

The output to the browser is this;
6Could not resolve host: (Error reading file)

If i run it in PHP CLI mode, with the following command, the output is the
desired html from

# php -f /path/to/testscript.php

Best regards,


Jeg beskyttes af den gratis SPAMfighter til privatbrugere.
Den har indtil videre sparet mig for at fa 14055 spam-mails.
Betalende brugere far ikke denne besked i deres e-mails.
Hent gratis SPAMfighter her:
Received on 2007-09-06