2

Running PHP 5.6 on an EC2 instance with Apache 2.4.18, I'm occasionally seeing errors in the log when trying to connect to an RDS database:

PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname

The problem seems to be specific to php_network_getadresses from within Apache. Everything outside of Apache can resolve the host just fine and a test PHP script running inside Apache that uses gethostbyname can successfully do the DNS lookup, too.

So far the system hasn't been active long enough for me to discern a real pattern to the outages but I think they might be related to the RDS maintenance window during the night.

I have seen other users ask the same, both on SF, the AWS forums and elsewhere, but the "solution" seems to be to restart Apache every now and then. I find this very unsatisfactory however, so I'm wondering whether there are better, canonical solutions to this?

1 Answers1

0

According to AWS, AWS puts a rate limit on DNS requests to protect from noisy neighbor effects. This way they can provided stable performance up to that limit, as apposed to having no limit but risk of unstable performance.

Configure an instance side DNS cache or use an outside DNS server like Google Public DNS solves the problem. In your case you could add the following lines to your /etc/resolv.conf file as a workaround: nameserver 8.8.8.8 and nameserver 8.8.4.4

  • I think that might eventually run into the same issue as is now happening on AWS - if your volume is high enough for AWS to start rate-limiting, one would assume the same would be likely for another DNS service. I think your suggestion to use instance-based DNS caches is probably more likely to solve the issue (and would probably also provide some degree of performance boost by reducing the latency associated with DNS). – iwaseatenbyagrue Apr 09 '17 at 09:44