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?
What had caused this error on my side was the following line
I managed to realize it was the culprit when i added the lines:
to all my php files.
To solve the
path issue
i canged the offending line to: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.
A weird thing I found was that the environment variable
SYSTEMROOT
must be set otherwisegetaddrinfo()
will fail on Windows 10.IMO it's the different way to resolve a name from the OS and PHP.
Try:
and
or
You should found some DNS/resolver error.
It is more flexible to use
curl
instead offopen
andfile_get_content
for opening a webpage.