• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$db['default']['pconnect'] = TRUE; and too many database connections error


I think the general practice in php, the default set up for persistent connection is 'FALSE'. I am using mysql.

Due to codeigniter set up the persistent connections as default.

1) There should NOT be any code logic difference in setting the mysql persistent connection to be true or false, right?

2) Why persistent connection to be true win the arguments? But at the same time, it seems to me more people in php/mysql community prefer that the persistent connection to be false? So persistent connection to be true win in CI must have good reasons, what are they? Thanks!

3) My server host dozens CodeIgniter sites, this persistent connections cause too many connection problems.

So I either to set up mysql server to allow connections to a very large number (or unlimited) or I have to set up mysql connection to be non-persistent in CodeIgniter by setting $db['default']['pconnect'] = FALSE; RIGHT?

What solution should I take? What are the advantages and disadvantages in these two approaches? For what kind cases (environments) I should which approach? Is that the choice between more loads on MySQL server or more loads on php?


Your question solved my problem, which in turn, may help you with your decision.

Within my CI application, I have 2 databases I use and need to connect to. One database (db1) holds tables pertaining to user user accounts and other site schema items. The other database (db2) holds data used to generate reports.

I am dynamically creating my menu system using a library. No matter what I tried, I couldn't get my library to switch over to the correct database when called within my default controller, as it kept reverting to db2. I then switched pconnect to FALSE and everything works just fine.

I think searain raises a good point. Today our CodeIgniter site ran into the too many connections error. We are running 1.7.2 (at present) with MySQL.

Since CI does go against the trend of using non-persistent connections, could you explain your reasoning?

Persistent connection is not an evil as I thought before.

Increase the allow connections to a large number and reduce the waiting time set up for mysql would solve the problem.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.