Welcome Guest, Not a member yet? Register   Sign In
Too many connections in MariaDB after CI and PHP upgrade
#1

Hi all:

I'm trying to update a project using Codeigniter 3.1.0 and PHP 7.0.6 (XAMPP) to Codeigniter 3.1.9 and PHP 7.3 (latest XAMPP) (Apache 2.4 and MariaDB 10.1 are common in both cases). I'm having the following problem:

Warning: mysqli::real_connect(): (08004/1040): Too many connections in C:\xampp73\htdocs\the_old_project\system\database\drivers\mysqli\mysqli_driver.php on line 201

Which immediately leads to:

Unable to connect to your database server using the provided settings.

The PHP configurations are the same for both versions, and the database server, even when it is not the same, shares the credentials, so PHPMyAdmin connects to both. I've increased the max_connections to 1024 in the latter database, but when I run the project with CI 3.1.0, it only uses 2 connections, but when I change the system folder for 3.1.9 it uses 1025 connections. I'm not using sessions in the database (so the migration steps related to sessions does not applies to this project)

Could you please suggest me where to search to find the origin of this issue? I can provide any other information/configurations needed to narrow down the search.

Thanks in advance!

P.S: Just in case, my config in application/config/database.php is:

$db['mysql_group'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'my_password',
    'database' => 'oldsystem_data',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
Reply
#2

Just for the record, we solve the problem, even when we are not sure when the behavior of the framework changed.

We realized that in our libraries we had something like a circular reference in the constructors (term used back in the old days of Pascal/Delphi Blush ). We removed the references, that luckily were there just for legacy reasons. We moved the only reference needed from the constructor to the function that actually used the other library. 

In CI 3.1.0, those references were solved somehow by the framework, but in 3.1.9 the same libraries were creating more than 8000 connections to MariaDB, all in sleep state...

Now is my turn to read all changelogs from 3.1.0 to 3.1.9 to understand what happened.

All the best!
Reply
#3

If you upgraded xampp then you need to redo your database settings xampp will over write all
of the previous settings

You can re-setup your database by doing the following, all of your databases will be gone with 
an xampp upgrade!

1) Exit your MySQL Server
2) Edit your  C:\xampp\mysql\bin\my.ini
3) Add the below to the file.

Code:
# The MySQL server
[mysqld]
##
## SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Your_new_password');
##
skip-grant-tables

4) Re-start your MySQL Server
5) Run phpMyAdmin - you should be able to get in now
6) Run the following SQL Query in phpMyAdmin

Code:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Your_new_password');

7) Exit your MySQL Server
8) Edit C:\xampp\mysql\bin\my.ini
9) Remark out the skip-grant-tables ( #skip-grant-tables )
10) You should be good to go.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

Actually, we did that, but then we realized that even with the old xampp, the same config in CI and the same credentials (that we left in a working copy in another Virtual Machine) the version 3.1.9 of CI didn't work either, and that we were able to connect to both databases with Navicat and PHPMyAdmin, using the project's credentials.

Moving back and forth with the system directory of CI 3.1.0 and 3.1.9 we were able to replicate the issue, and then we decide to left the database alone and focus on the project, since the logs of CI weren't showing anything useful. Applying the old-but-effective method of var_dump, log to file and echo we were able to isolate the problem in the load function of a library, and from that point on we started looking into the constructors, where we found the circular references. We solved that and up to now, everything seems to be working fine.

Best regards!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB