Every 5 to 10min, our webapp (PHP 7.4 - Symfony) is experiencing an error trying to access an RDS database. We used to host our DB on a EC2 instance and it worked fine. Since the migration we have this problem.
As of today I tried :
- Checking the connection credentials : they are correct
- Checking if it was a DNS resolution limitation : it was not
- Upgrade the instance type of the RDS instance : the problem is still here
- Checked the max packets allowed by MYSQL and other such parameters : the values are the same as the old DB
Here is the error I am getting :
`[2023-12-05 11:27:03] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known" at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 112
{"exception":"[object] (Doctrine\DBAL\Exception\ConnectionException(code: 0): An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /var/www/***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:112, Doctrine\DBAL\Driver\PDO\Exception(code: 2002):
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /var/www/html/clic-and-fit/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 2002):
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40, PDOException(code: 0):
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known at /***/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40)"} []`
EDIT : I tried to use the IP address associated with the RDS endpoint, and it seems to solve the problem. So it looks like it is a DNS issue. Either an EC2 limitation or a VPC limitation. But the thing is, I tested how many DNS requests my instance is launching each second, and it is way below the 1024 limit. So I am going to be setting up a DNS cache on my server to solve the issue.
Hello,
Thank you for you answer. I tried clearing the cache, restarting PHP-FPM and Apache2 and it didn't resolve the issue