Question:
PHP/cURL - Only able to query local websites - Help.?
Jaypoc
2011-09-15 19:07:02 UTC
I was having trouble with an XML parsing script and found the issue to be CURL. Using the code below to test cURL, I tried to load both locally hosted sites and remotely hosted sites. The local sites loaded right away while the remote sites return the error, "couldn't connect to host" (I tried many including "http://www.google.com/"

When I run CURL from a bash shell, it works regardless of what site I call.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mysite.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if($contents) {
echo $contents;
} else {
echo curl_error($ch);
}

curl_close($ch);
?>

In addition, I don't see any errors in the apache logfiles. What could be blocking the requests? Is there additional configuration for cURL that I can't find that would enable/disable remote requests?

From my PHPINFO:
cURL support enabled
libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.8 libssh2/0.18
Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny9 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2
mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0
Three answers:
anonymous
2011-09-15 19:18:46 UTC
Check your firewall rules? (are you using iptables as your firewall?)... Nevermind... Looks like you got it running from command line



What about trying file_get_contents just to see if that can grab an external site?
anonymous
2016-10-21 17:16:50 UTC
i latterly had to correctly known the hollow cases of the community tip and it wasn't there so I regarded on the area of the closest council and refered to that, loaded up the motor vehicle drove each of ways there to discover that my tip closed an hour until now, I wasn't maximum suitable extremely joyful.
Frank
2011-09-15 19:13:07 UTC
Your ISP is firewalling you. See my source:


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...