mysql - PHP SQL query reaches max_user_connections

WBOY
Release: 2016-07-06 13:51:38
Original
1396 people have browsed it

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?

Reply content:

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template