We have a website written in PHP hosted on AWS EC2 instance, talking to AWS RDS database. When high traffic on the site, some users are experiencing 503 error on pages and we can see these errors on our Apache log:
Uncaught Exception: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on ...
My initial though is there were too many connections from PHP, which exceeds the max limit of RDS. However, this is the what I got from RDS
show variables like '%conn%';
connect_timeout 10
max_connect_errors 100
max_connections 2486
max_user_connections 0
And the RDS monitoring tells me that actual DB connections was less than 300.
Do I miss anything here?
This is the code that builds the connection if uesful:
$dbh = new PDO('mysql:host='.$db_host.';dbname='.$wp_db_name, $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;