The program in question is a skin station, which often requires database queries. I have a database class based on mysqli encapsulation, and I wrote a statement to close the current database connection in __destruct()
to ensure that a large number of useless connections are not left.
However, recently some users have reported User 'u173999462_rg' has exceeded the 'max_user_connections' resource (current value: 3)
error reports, reaching the upper limit of the maximum number of connections.
Because MySQL does not limit max_user_connections
by default, I didn’t pay special attention during development and just closed the connection in the destructor. Isn't this the only way to do it?
Program database class address: @GitHub
Is there any optimization method?
The program in question is a skin station, which often requires database queries. I have a database class based on mysqli encapsulation, and I wrote a statement to close the current database connection in __destruct()
to ensure that a large number of useless connections are not left.
However, recently some users have reported User 'u173999462_rg' has exceeded the 'max_user_connections' resource (current value: 3)
error reports, reaching the upper limit of the maximum number of connections.
Because MySQL does not restrict max_user_connections
by default, I didn’t pay special attention during development and just closed the connection in the destructor. Isn't this the only way to do it?
Program database class address: @GitHub
Is there any optimization method?
Looking for the singleton mode of PHP should be able to solve the problem. The problem you encountered is that the MySQL connection cannot be reused
1. To make it simple, just set this value high
2. Improving the machine configuration can also solve the problem
3. Isn’t the cache used? My understanding is that if the data is not updated frequently, just store it in redis and create a caching strategy.