I've got a tiny bit of code running on my mac dev server that fails with a "couldn't resolve host" error. I've tried typing 'curl http://www.domain.com/file.txt' at the command line and it echoes out the entire file with no problems so I know it's not a network problem. The code looks pretty straightforward:
$csv = 'http://www.domain.com/file.txt';
$tmp_file_name = 'tmp/'.numOnly(microtime(true)).'.txt';
$ch = @curl_init();
$fp = @fopen($tmp_file_name, 'w');
@curl_setopt($ch, CURLOPT_URL, $csv);
@curl_setopt($ch, CURLOPT_FILE, $fp);
@curl_setopt($ch, CURLOPT_FAILONERROR, 0);
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
@curl_setopt($ch, CURLOPT_TIMEOUT, 16);
@curl_setopt($ch, CURLOPT_VERBOSE, 1);
if(@curl_exec($ch) === false){
die(@curl_error($ch));
}else{
echo 'success!';
}
@curl_close($ch);
@fclose($fp);
My curl settings in phpinfo look like this:
cURL support enabled
cURL Information 7.16.4
Age 3
Features
AsynchDNS No
Debug No
GSS-Negotiate Yes
IDN No
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI No
krb4 No
libz Yes
CharConv No
Protocols tftp, ftp, telnet, dict, ldap, http, file, https, ftps
Host i386-apple-darwin9.0
SSL Version OpenSSL/0.9.7l
ZLib Version 1.2.3
Can anyone suggest a good reason why curl would fail when run under apache while it works fine from the command line?