Codeigniter __construct()连接过多 [英] Codeigniter Too many connection __construct()
问题描述
我正在使用CI3.X。现在在我的应用程序中,我使用多个数据库。现在我的托管服务器最多允许100个连接,所以我的应用程序就掉了。
I am using CI 3.X. Now in my app I using multiple database. Now my hosting server allows max 100 connections, So my app gets down.
在我的数据库配置中,我将 PCONNECT设置为FALSE 。
In my database configurations I have kept PCONNECT to FALSE .
现在我的结构如下:
我有一个基本控制器 MY_Controller ,它可以扩展到 CI_Controller 。
I have a base controller MY_Controller which extends to CI_Controller.
然后我有一个 Customer_Controller ,它扩展到MY_Controller。
Then I have a Customer_Controller which extends to MY_Controller.
在Customer_Controller中,我加载了辅助数据库。而且这个Customer_Controller位于库文件夹中。
In Customer_Controller I load my secondary database. And this Customer_Controller lives in libraries folder.
我所有其他控制器都扩展到该控制器。
All my other controller extend to this controller.
那我哪里出问题了?为什么我的MySQL服务器会收到此错误????
So where Am I going wrong ? Why does my MySQL sever gets this error ???
我得到的错误是:
遇到PHP错误
A PHP Error was encountered
严重性:警告
消息:mysqli :: real_connect() :(HY000 / 1040):连接太多
Message: mysqli::real_connect(): (HY000/1040): Too many connections
文件名:mysqli / mysqli_driver.php
Filename: mysqli/mysqli_driver.php
行号: 202
回溯:
文件:/application/core/MY_Controller.php行:7功能:
__construct
File: /application/core/MY_Controller.php Line: 7 Function: __construct
文件:/application/libraries/Admin_Controller.php行:7功能:
__construct
File: /application/libraries/Admin_Controller.php Line: 7 Function: __construct
文件:/application/controllers/admin/Dashboard.php行:16函数:
__construct
File: /application/controllers/admin/Dashboard.php Line: 16 Function: __construct
文件:index.php行:315函数: require_once
File: index.php Line: 315 Function: require_once
推荐答案
您将需要增加 max_connections
在您的MySQL配置文件中。该文件的可能位置是: /etc/my.cnf
。
You will need to increase the value of max_connections
in your MySQL configuration file. Possible location for the file is: /etc/my.cnf
.
在文件上增加 max_connections
系统变量:
On the file increase the value of max_connections
system variable:
[mysqld]
set-variable=max_connections=500
或者,您也可以从MySQL关闭持久连接。
Alternatively, you can also turn off persistent connection from MySQL.
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent=Off
这篇关于Codeigniter __construct()连接过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!