tags:

views:

60

answers:

2

I have the following PHP code that uses cURL:

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,"http://area51.stackexchange.com/users/flair/31.json");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

$a_data = json_decode(curl_exec($ch));

echo curl_error($ch);

I then get the following error when I try to access the page over HTTP:

Failed to connect to 0.0.0.31: Invalid argument

However, the code works fine when run from the command line.

What could possible cause cURL to try to connect to 0.0.0.31, which is AFAIK, not even a valid IP address?

+2  A: 

"What could possible cause cURL to try to connect to 0.0.0.31, which is AFAIK, not even a valid IP address?"

Your DNS is botched. I tested your code and it works.

Enemy of the State
A: 

When you say "the code works fine when run from the command line," do you mean you have run it with the PHP CLI interpreter? If that's the case, you might check for any noticeable mismatches between the output of php -i vs. phpinfo() on the web server. It might be some strange version mismatch or environment problem, although your guess is as good as mine.

If you are (as I had originally thought) just talking about running the curl command, you could try checking version numbers or environment variables there too.

Tim Yates