Intermittent error when accessing RDS database with PHP 7.4

0

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.

已提问 5 个月前423 查看次数
2 回答
0

Hello.

If you are using Symfony, why not try clearing the cache with the following command?
Please also try restarting the web server such as Apache.

php app/console cache:clear
profile picture
专家
已回答 5 个月前
  • Hello,

    Thank you for you answer. I tried clearing the cache, restarting PHP-FPM and Apache2 and it didn't resolve the issue

0

Whats the DB version and try checking the timeout settings on PHP and MySQL level. Updated PHP drivers to match the DB version? if you are allowing persistent connection or connection pooling, need to make sure those are not killed due to idle timeout.

Krishna
已回答 5 个月前
  • 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

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容