1

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:

  1. The URL exists and gives a valid result in the browser.
  2. I've ensured that allow_url_fopen is on in php.ini.
  3. I've changed to Google Public DNS in /etc/resolv.conf.
  4. Doing ping google.com works.
  5. Switching to http://0.0.0.0/path/to/json works but is undesirable.
  6. I've got a couple of domains pointing to the same server, and the same problem occurs independently.

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.

Ivar
  • 4,344
  • 6
  • 38
  • 53

3 Answers3

1

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!

Ivar
  • 4,344
  • 6
  • 38
  • 53
0

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.

BogdanM
  • 625
  • 1
  • 6
  • 10
  • But there was no difference when I switched from the original nameservers to the Google Public DNS. Do you recommend any other nameserver? – Ivar Sep 20 '13 at 09:35
  • Can you use whois and dig to see what they tell you? Post it here as well. `dig yourwebsite.com @ns1.yourdnsserver.com` – BogdanM Oct 01 '13 at 14:06
0

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.

Muktadir
  • 115
  • 8