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.
Can this be fixed in a similar way?
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.
I had this problem, it was because the value of default_socket_timeout in php.ini was too small.
I would try doubling its value in your case to see if it fixes the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With