問題描述
大家好.我有一個奇怪的錯誤.我創建了一個這樣的聊天:
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 - 數據庫連接過多錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!