Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP php_network_getaddresses: getaddrinfo failed: No such host is known

I am having DNS issues with a certain target domain. I am using fopen() (but same issue with other functions) to retreive an image, but I get this error: Warning: fopen(): php_network_getaddresses: getaddrinfo failed: No such host is known

I am able to ping or nslookup the domain from the command prompt, but for some reason php throws this error. When I try fopen('http://www.google.com', r); or other domains, all goes fine. But above mentioned domain simply won't resolve with PHP. I have flushed the DNS, restarted Apache, but still no luck..

I have tried with:

  • Windows 7, Apache 2.2 PHP 5.3.6
  • Windows server 2008r2, Apache 2.2 PHP 5.3.6

What can cause this single domain to not resolve?

like image 763
Richard Avatar asked Nov 21 '11 10:11

Richard


4 Answers

IMO it's the different way to resolve a name from the OS and PHP.

Try:

echo gethostbyname("host.name.tld");

and

var_export (dns_get_record ( "host.name.tld") );

or

$dns=array("8.8.8.8","8.8.4.4");
var_export (dns_get_record ( "host.name.tld" ,  DNS_ALL , $dns ));

You should found some DNS/resolver error.

like image 159
Ivan Buttinoni Avatar answered Nov 18 '22 18:11

Ivan Buttinoni


Your "localhost" cannot resolve the name www.google.com, which means your machine doesn't/can't reach a valid dns server.

Try ping google.com on the console of that machine to verify this.

like image 28
anil Avatar answered Nov 18 '22 18:11

anil


It is more flexible to use curl instead of fopen and file_get_content for opening a webpage.

like image 2
Mostafa Lavaei Avatar answered Nov 18 '22 19:11

Mostafa Lavaei


getaddrinfo failed: No such host is known

The above error is caused due to mistake in Database Host (DB_HOST) in .env file

Open the .env file and Specially check for this env variables

DB_HOST=localhost
DB_DATABASE=database_name
DB_USERNAME=database_username
DB_PASSWORD=database_password
like image 1
Omkar Ghurye Avatar answered Nov 18 '22 18:11

Omkar Ghurye