views:

39

answers:

1

Hello all,

When we use file_get_contents, what does PHP use to resolve the domain name (local DNS??).

I ask because I got this error:

Warning: file_get_contents(http://external-domain.com) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\test.php on line 11

I managed to fix this exact error previously when I used file_get_contents on an internal URL i.e. http://localhost:9090, the problem was that I didn't have a mapping of localhost to 127.0.0.1 in my hosts file on my windows machine. After adding this, I was able to use file_get_contents on internal URLs.

Now I am wondering, this can be fixed in a similar way?

Thanks all for any help

A: 

Are you behind a proxy? If so, you'll need to tell PHP about it using stream_context_set_default or by passing a context created with stream_context_create as the third param to file_get_contents.

bradym