开发者社区> 问答> 正文

PHP Mysqli数据库连接池,以避免最大用户数

I surfed on Internet for past two days to create the DB pooling by PHP, but not yet achieved. I'm using PHP and MySQLi. We bought the mysqli db with 15 Maximum user connection. I want to pool the db connection to avoid the new connection. I used

persistent

as well as

mysqli_connect

. but I don't feel much different both are creating the new connection since other user already logged in. I was trying this function to get

connection.

 <?php
function getConnection(){
    if ($connect){
        return $connect;
    }else{
        $connect = new mysqli('p:xxxx','yyy','zzz','aaaa');
        return $connect;
        if(mysqli_connect_errno($connect))
        {
            echo "Server Busy";
        }
    }
}
 ?>

But above function only returns the else part. Please suggest me how to handle this. Thanks in advance. For now I'm killing the process which are in sleep mode to reduce the probability of increasing DB connection.

遇到了同样的问题,在CSDN看到了,希望阿里云团队能够给出正确、标准的答案~请查看

展开
收起
刘刚_ 2020-05-23 21:07:12 781 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-直面PHP微服务架构挑战-高驰涛 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载