Paulraj
Paulraj

Reputation: 3397

file_get_contents(): No such host is known error

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?

Upvotes: 4

Views: 12669

Answers (3)

CodeLikeNoonesBusiness
CodeLikeNoonesBusiness

Reputation: 677

It is because you need to turn on allow_url_fopen in php.ini

Upvotes: 3

rahul
rahul

Reputation: 1

Check your localhost and username.

Like if you are using Xampp, in the host column type Localhost and the database name and last but not least the username with root, and then install.

It's quite easy but if you missing it, it's gone be very upsetting.

Upvotes: 0

VolkerK
VolkerK

Reputation: 96159

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.

Upvotes: 8

Related Questions