Reputation: 4392
Okay, this question has been asked plenty of times around the internet, but I haven't found any solution that fixes the problem in my case.
I'm about to fetch some JSON data with this code:
$response = file_get_contents('http://www.domain.com/path/to/json');
And it's constantly stumbling over the following error:
file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known
I'm running Debian with PHP 5.4.4 on Nginx 1.2.6 and php-fpm.
This is my troubleshooting so far:
allow_url_fopen
is on in php.ini./etc/resolv.conf
.ping google.com
works.http://0.0.0.0/path/to/json
works but is undesirable.I'm a bit concerned about the domain
in /etc/resolv.conf
, is it right?
# Automatically generated by OnApp (2.3.0-29)
domain localdomain
# Original DNS
#nameserver 10.0.10.10
#nameserver 10.0.11.11
# Google Public DNS
nameserver 8.8.8.8
nameserver 8.8.4.4
Any kind of help is appreciated.
Upvotes: 1
Views: 6137
Reputation: 115
I got it solved in two ways, either run php (or apache) in root user mode or update your debian package. It's probably debian7u5 or update 4 who has this bug.
Upvotes: 0
Reputation: 4392
I hate to say this, but the problem solved itself; I just upgraded the Debian packages (apt-get upgrade
) and the problem went away. Frustrating to not know the cause, though.
Thank you all for your time!
Upvotes: 1
Reputation: 635
It's most likely a DNS problem. If IP works but domain has problems you should look into the DNS. That's what "name or service not known" hints to. If you can, use different nameservers. I think google's dns can't translate your domain to the ip.
Upvotes: 0