file_get_contents(): No such host is known error
Solution 1
Your "localhost" cannot resolve the name google.com to an ip address, which means your machine doesn't/can't reach a valid dns server.
This probably doesn't only affect php. Try ping google.com
on the console of that machine. Does this complain about the unknown host, too?
The steps necessary to solve the problem depend on what your "localhost" is (operating system, flavour/distribution, ...) and how it is connected to the internet.
Solution 2
It is because you need to turn on allow_url_fopen in php.ini
Paulraj
Passionate Programmer who loves to code. Angular, Typescript, Javascript, Kendo-UI, PHP, Python, Mysql, MongoDB, Codeigniter, Zend, Laravel, Drupal.
Updated on June 20, 2022Comments
-
Paulraj almost 2 years
I am using the
file_get_contents
function to get the URL into a string:$contents = file_get_contents("http://google.com");
But, I am getting the following error:
file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: No such host is known.
How can I solve this in my localhost?
-
RaYell over 14 yearsI think this may be DNS or firewall issue. Can you check if you can
ping google.com
from that host? -
Kamlesh almost 3 years
ping google.com
works in command line but getting same issue.
-
-
Paulraj over 14 yearswhen i give ping google.com it says unknown host. i check with my host. thanks.
-
ESP32 over 8 yearsThat's not correct - if that was the case the server would return someting like "failed to open stream: no suitable wrapper could be found" or "URL file-access is disabled in the server configuration"
-
Kamlesh almost 3 years
ping google.com
works in command line but getting same issue -
Kamlesh almost 3 years
allow_url_fopen
is Already ON but still not working