Good day to all. I have an odd error. I have created a chat that works like this:
Please check if you open up a new connection with each of your requests (mysql_connect(...)). If you do so, make sure you close the connection afterwards (using mysql_close($link)).
Also, you should consider changing this behaviour as keeping one steady connection for each user may be a better way to accomplish your task.
If you didn't already, take a look at this obvious, but nonetheless useful information resource: http://php.net/manual/function.mysql-connect.php
If you are reaching the mac connection limit
go to /etc/my.cnf
and under the [mysqld]
section add
max_connections = 500
and restart MySQL.
There are a bunch of different reasons for the "Too Many Connections" error.
Check out this FAQ page on MySQL.com: http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html
Check your my.cnf file for "max_connections". If none exist try:
[mysqld]
set-variable=max_connections=250
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.
The error SQLSTATE[HY000] [1040] Too many connections
is an SQL error, and has to do with the sql server. There could be other applications connecting to the server. The server has a maximum available connections number.
If you have phpmyadmin, you can use the 'variables' tab to check what the setting is.
You can also query the status table like so:
show status like '%onn%';
Or some variance on that. check the manual for what variables there are
(be aware, 'connections' is not the current connections, check that link :) )
This can happen due to too many connection same time or many chat at same time. Also it can happen due too many session.
The best way to sort out this issue is restart MySQL.
service mysqld restart
or
service mysql restart
or
/etc/init.d/mysqld restart
If you need to increase MySQL Connections without MySQL restart do like below, also if you don't know configuration file, below use the mysqlworkbench or phpmyadmin or command prompt to run below queries.
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL max_connections = 250;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 250 |
+-----------------+-------+
1 row in set (0.00 sec)
These settings will change at MySQL Restart.
For permanent changes add below line in my.cnf and restart MySQL.
max_connections = 151