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.

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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠