mysql - PHP SQL 查询达到 max_user_connections

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

出现问题的程序是个皮肤站,经常需要进行数据库查询。自己有基于 mysqli 封装的一个数据库类,在 __destruct() 里写入了关闭当前数据库连接的语句以保证不会留下大量无用连接。

然而最近有用户反馈出现了 User 'u173999462_rg' has exceeded the 'max_user_connections' resource (current value: 3) 报错,达到了最大连接数的上限。

因为 MySQL 默认是不限制 max_user_connections 的,所以开发的时候也没有特别注意,只是在析构函数里关闭了连接。单单这样是不行的吗?

程序数据库类地址:@GitHub

请问有什么优化方法吗?

回复内容:

出现问题的程序是个皮肤站,经常需要进行数据库查询。自己有基于 mysqli 封装的一个数据库类,在 __destruct() 里写入了关闭当前数据库连接的语句以保证不会留下大量无用连接。

然而最近有用户反馈出现了 User 'u173999462_rg' has exceeded the 'max_user_connections' resource (current value: 3) 报错,达到了最大连接数的上限。

因为 MySQL 默认是不限制 max_user_connections 的,所以开发的时候也没有特别注意,只是在析构函数里关闭了连接。单单这样是不行的吗?

程序数据库类地址:@GitHub

请问有什么优化方法吗?

找找PHP的单例模式看看应该就能够解决问题le,你遇到的问题是不能够复用MySQL连接的问题

1、简单一点,把这个数值设置高就可以了
2、提高机器配置,也可以解决
3、难道没用缓存?我理解是如果数据更新不频繁,直接 redis 放着,做个缓存策略就可以了。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!