EDIT: I don't understand why my question was closed because the other question is nothing at all like my question. That's asking why we shouldn't use mysql_ functions. I'm not asking that at all. I'm asking why I'm having connections denied even though I'm not at my connection limit.
I'm connecting to MySQL using both mysql_connect and PDO. (I'm working towards PDO exclusively but I have almost 2000 statements that need to be updated so it's a work in progress).
$conn = mysql_connect($dblocation, $dbusername, $dbpassword) or die ("<span style='color:red'>Unable to connect! Press F5 to try again.</span>");
mysql_select_db($dbname, $conn) or die ("Unable to select database!");
try{
$pdo = new PDO("mysql:host=$dblocation;dbname=$dbname", $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch(PDOException $ex){
echo (json_encode(array('outcome' => false, 'message' => 'Unable to connect using PDO')));
}
This has been working fine for years, but my server has gotten busier over time. The last couple of days my users have been complaining about getting connection errors. Either "Unable to connect! Press F5 to try again." or "Unable to connect using PDO". Today it's gotten progressively worse.
It's happening mostly in the morning and late afternoon, as those are the busy times on the server. The weird thing is that I'm nowhere near my connection limit. My connection limit is set to 2200 and my connections are peaking below 200, and I'm getting the error even when I have less than 100 connections.
How can I be getting connection errors, when I'm not at my connection limit?