“无法连接.连接过多" MySQLi中的错误 [英] "Could not connect. Too many connections" Error in MySQLi

查看:48
本文介绍了“无法连接.连接过多" MySQLi中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

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{ 
        return $db_conn; 
    }
}

//close db connection
function closeDBConn( $params ){
    $db_conn = $params['db_conn'];
    $db_conn->close;
}

//used as below
$db_conn = openDBConn();

save_new_post( $post_txt, $db_conn );

closeDBConn( array('db_conn'=>$db_conn));

我有时会收到无法连接.连接太多"错误. 当我让Google机器人扫描我的网站时,就会发生这种情况.

From time to time, I get the "Could not connect. Too many connections" error. This tends to happen when I have Google bot scanning my website.

自从MySQL升级到MySQLi以来,这个问题似乎已经开始. 关于如何确保所有连接都关闭有任何建议吗?

This problem seems to have started ever since upgrading to MySQLi from MySQL. Is there any advice on how ensure all connections are closed?

谢谢

推荐答案

您需要增加与MySQL服务器的连接数(默认值仅为100,通常每个页面加载会消耗一个连接)

You need to increase the number of connections to your MySQL server (the default is only 100 and typically each page load consumes one connection)

编辑/etc/my.cnf

max_connections = 250

max_connections = 250

然后重新启动MySQL

Then restart MySQL

服务mysqld重新启动

service mysqld restart

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

这篇关于“无法连接.连接过多" MySQLi中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆