Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents(): No such host is known error

Tags:

php

networking

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?

like image 574
Paulraj Avatar asked Dec 22 '22 09:12

Paulraj


1 Answers

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.

like image 61
VolkerK Avatar answered Jan 03 '23 00:01

VolkerK