[php] 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?

This question is related to php fopen getaddrinfo

The answer is


Your target domain might refuse to send you information. This can work as a filter based on browser agent or any other header information. This is a defense against bots, crawlers or any unwanted applications.


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


A weird thing I found was that the environment variable SYSTEMROOT must be set otherwise getaddrinfo() will fail on Windows 10.


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.


What had caused this error on my side was the following line

include_once dirname(__FILE__) . './Config.php';

I managed to realize it was the culprit when i added the lines:

//error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
//ini_set('display_errors', 1);

to all my php files.

To solve the path issue i canged the offending line to:

include_once dirname(__FILE__) . '/Config.php';