Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've already read all the questions / answers about this subject here on stack overflow but unfortunately none have resolved my problem.

In the last few days the mysql error "too many connections" keeps showing up on the website logs and it hangs the entire website for every client. In fact it hangs all the websites on the server.

So here are my questions / remarks:

  • there are about 50 different client databases, besides 2 which are common to all clients
  • pconnect is already = FALSE for all connections
  • On the file "php.ini" the variable "allowpersistent" is ON. Does this make the mysql connections permanent even if I write pconnect = FALSE? (I can't change the "allowpersistent" variable, would have to ask the hosting company)
  • There are 3 files that load databases, one loads the client's DB and the other two load common databases for all clients, they are called on the construct method of every model, but CI supposedly should close the mysql connections after its done with them AND ignore any "load->database" already loaded
  • "db->close" apparently does nothing, because this->db->database keeps its value after I close it :P
  • Threads_connected are up to 1000 as I write this and the website is down :(
  • mysql configuration has max_connections = 1000, can it be further increased? I see no change in free memory, so what can happen?
  • Should I change to PDO? I'm using dbdriver "mysqli"
  • Should I ask the hosting company to lower the mysql variable 'wait_timeout', so as to rapidly close the DB connection?
  • Should I update CodeIgniter? I have version 3.1.4 and it's now at 3.1.9

Many thanks for your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
599 views
Welcome To Ask or Share your Answers For Others

1 Answer

In our case the solution was lowering the mysql variable "wait_timeout" from 8 hours (the default, wtf!?) to 180 seconds. And it can still be lowered more if needed. This had to be done by the hosting company, as we do not have root access to our server.

All the other solutions I mentioned in the question were not working, like "pconnect = false" and "db->close".

"Threads_connected" are now always under 100 or 200, instead of the almost 1000 from before this fix.

My team wrestled with this problem for two days, and there's lots of people on the Web asking for solutions but without any (working) answers.

Cheers :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...