0

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.

enter image description here

enter image description here

How can I be getting connection errors, when I'm not at my connection limit?

Vincent
  • 1,741
  • 23
  • 35
  • What error are you getting? – Dharman Mar 15 '23 at 23:52
  • I'm just getting the error I'm echoing out in my connect script (Unable to connect! Press F5 to try again), which tells me mysql_connect is returning false. That's not much to go on. – Vincent Mar 16 '23 at 00:00
  • Yes, but what does `mysql_error` give you? – Dharman Mar 16 '23 at 00:01
  • I don't have that in my script. Was not aware of that function. I will have to add it. – Vincent Mar 16 '23 at 00:08
  • You should also check `SHOW GLOBAL STATUS LIKE 'max_used_connections';` to check the high-water mark. That will tell you if the max connections was reached in the past, because it can be too brief for you to observe by viewing the current `Threads_connected`. – Bill Karwin Mar 16 '23 at 00:11
  • I just checked it and it showed that it reached 1861. Still not my max, but pretty darn high. Is there any way to tell when that happened? Or could this have been three years ago? nvm, I see that this is since the server started, so since my last reboot. – Vincent Mar 16 '23 at 00:14
  • @Vincent SHOW GLOBAL STATUS LIKE "max_used_conn%"; will show you both the count and time of the highest count. Here if you need me. View profile for contact info. – Wilson Hauck Mar 16 '23 at 00:24

0 Answers0