Sunday, 15 February 2015

php - "Could not connect. Too many connections" Error in MySQLi -



php - "Could not connect. Too many connections" Error in MySQLi -

i have next code

function opendbconn($params){ $conn_mode = $params['conn_mode']; $db_conn = $params['db_conn']; //create connections if(empty($db_conn->info)) { $db_conn = new mysqli("localhost", $user, $password, "database"); $db_conn->set_charset('utf8'); $mysqli_error = $db_conn->connect_error; } if($mysqli_error !== null){ die('could not connect <br/>'. $mysqli_error); }else{ homecoming $db_conn; } } //close db connection function closedbconn( $params ){ $db_conn = $params['db_conn']; $db_conn->close; } //used below $db_conn = opendbconn(); save_new_post( $post_txt, $db_conn ); closedbconn( array('db_conn'=>$db_conn));

from time time, "could not connect. many connections" error. tends happen when have google bot scanning website.

this problem seems have started ever since upgrading mysqli mysql. there advice on how ensure connections closed?

thanks

you need increment number of connections mysql server (the default 100 , typically each page load consumes 1 connection)

edit /etc/my.cnf

max_connections = 250

then restart mysql

service mysqld restart

http://major.io/2007/01/24/increase-mysql-connection-limit/

php mysqli runtime-error

No comments:

Post a Comment