Rajan
Rajan

Reputation: 2425

Codeigniter Too many connection __construct()

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.

In my database configurations I have kept PCONNECT to FALSE .

Now My Structure is as follow:

I have a base controller MY_Controller which extends to CI_Controller.

Then I have a Customer_Controller which extends to MY_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.

So where Am I going wrong ? Why does my MySQL sever gets this error ???

the error i get it:

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/1040): Too many connections

Filename: mysqli/mysqli_driver.php

Line Number: 202

Backtrace:

File: /application/core/MY_Controller.php Line: 7 Function: __construct

File: /application/libraries/Admin_Controller.php Line: 7 Function: __construct

File: /application/controllers/admin/Dashboard.php Line: 16 Function: __construct

File: index.php Line: 315 Function: require_once

Upvotes: 0

Views: 5532

Answers (1)

You will need to increase the value of max_connections in your MySQL configuration file. Possible location for the file is: /etc/my.cnf.

On the file increase the value of max_connections system variable:

[mysqld]
set-variable=max_connections=500

Alternatively, you can also turn off persistent connection from MySQL.

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent=Off

Upvotes: 2

Related Questions