We call $db = ADONewConnection($CFG->dbtype); at evey page refresh,
however looking closer, ADOdb helps us with creating a persistent
connection if out $CFG->dbpersist is true.

I was unable to replicate this on a Postgres DB.

 $db = ADONewConnection($CFG->dbtype);
    if (empty($CFG->dbhost)) {
        $CFG->dbhost = '';
    }
    // The ADODB connection function doesn't have a separate port argument, but 
the
    // postgres, mysql, and mysqli drivers all support a $this->dbport field.
    if (!empty($CFG->dbport)) {
        $db->port = $CFG->dbport;
    }
    if (!empty($CFG->dbpersist)) {    // Use persistent connection (default)
        $dbconnected = 
$db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
    }
    else {                                                     // Use single 
connection
        $dbconnected = 
$db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
    }

ADOdb's PConnect uses the new connection to persist the current one,
whereas their Connect doesn't.

References:
https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:adonewconnection
https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:connect - simply 
establishes a connection

Other checks I would make is to make sure the config is set:
- $CFG->dbtype is set to mysqli and that the extension_loaded is true
- $CFG->dbpersist is not set to true. If it is not set, it will create a new 
connection each time.

However, one thing I am unsure of in the following code is where we set
$CFG->dbpersist is set. When I debug this, it skips the persist
function, so I must be creating a new connections each time locally too.

** Changed in: mahara
       Status: Triaged => In Progress

-- 
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: mahara-contributors
https://bugs.launchpad.net/bugs/1887321

Title:
  too many DB connections

Status in Mahara:
  In Progress

Bug description:
  From forum post
  
https://mahara.org/interaction/forum/topic.php?id=8654&offset=0&limit=10#post34439

  By what is reported in this forum post, it looks like the amount of
  connections by DB username is over 50 even when it's only one mahara
  account logged in on the site.

  We have to look into why this is happening, if we are opening
  connections but never closing them.

  By a quick search I could find that we are calling
  $db = ADONewConnection($CFG->dbtype);
  from init.php everytime, there are no checks for conditions so we always 
create a new connection
  but we are not calling the Disconnect function from ADOConnection to kill the 
connection.

  The forum post resports this for mysqli but we should check if we have
  the same problem with postgres as well

To manage notifications about this bug go to:
https://bugs.launchpad.net/mahara/+bug/1887321/+subscriptions

_______________________________________________
Mailing list: https://launchpad.net/~mahara-contributors
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~mahara-contributors
More help   : https://help.launchpad.net/ListHelp

Reply via email to