php, mysql - Too many connections to database error(php, mysql - 数据库连接过多错误)
问题描述
大家好.我有一个奇怪的错误.我创建了一个这样的聊天:
Good day to all. I have an odd error. I have created a chat that works like this:
- 问题/答案被插入到数据库中
- 每 2 秒向一个 php 脚本发送一个 ajax 请求以获取新的问题/答案
直到今天我收到此错误时它都运行良好:
It worked fine until today when I got this error:
Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php:129
Stack trace: #0 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=loca...', '', '', Array)
s#1 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
s#2 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect()
s#3 /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('select profile_...', Array)
s#4 /var/www/html/dbdev/include/Zend/Db/Adapter/Abstract.php(782): Zend_Db_Adapter_Pdo_Abstract->query('select profile_...', Array)
s#5 /var/www/html/dbdev/include/Profile.php(43): Zend_Db_Adapter_Abstract->fetchPairs('select profile_...')
s#6 /var/www/html/dbdev/public_html/index.php(29): Profile->load()
s#7 {main} Next exception 'Zend_Db_Adapter_Exception' with in /var/www/html/dbdev/include/Zend/Db/Adapter/Pdo/Abstract.php on line 144
问题是我们没有那么多...(8)而且我认为数据库不能同时支持超过 8 到 16 个连接(在规范上写的是聊天必须支持 50-100 个用户所以8是......小).
The problem is that we were not that many... (8) and I don't think the db could not support more than 8 to 16 connections simultaneously (on specifications is written that the chat must support 50-100 users so 8 is... small).
所以...谁能告诉我为什么会发生这种情况(昨天我们 15 岁并且工作正常)以及如何解决它?谢谢您的帮助.如果您需要任何代码示例,请询问.
So... can any1 tell me why did this happen (yesterday we were 15 and worked fine) and how to solve it? Thank you for your help. If you need any code samples just ask.
推荐答案
Too Many Connections"错误的原因有很多.
There are a bunch of different reasons for the "Too Many Connections" error.
在 MySQL.com 上查看此常见问题解答页面:http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html
Check out this FAQ page on MySQL.com: http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html
检查您的 my.cnf 文件中的max_connections".如果不存在尝试:
Check your my.cnf file for "max_connections". If none exist try:
[mysqld]
set-variable=max_connections=250
但是默认值是 151,所以你应该没问题.
However the default is 151, so you should be okay.
如果您在共享主机上,可能是其他用户占用了太多连接.
If you are on a shared host, it might be that other users are taking up too many connections.
需要注意的其他问题是持久连接的使用和磁盘空间不足.
Other problems to look out for is the use of persistent connections and running out of diskspace.
这篇关于php, mysql - 数据库连接过多错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php, mysql - 数据库连接过多错误
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01