简体   繁体   中英

Codeigniter Multi Tenant Takes long time in loading tenant database

I am developing a multi tenant app in CodeIgniter, where every tenant has its own db. At run time I find the tenant name and then load its db info from my master database. In My_Model a function establishes connection with slave database

function getDbConFig() {
    $dsn = 'mysql://'.$this->dbs_user.':'.$this->dbs_pwd.'@'.$this->dbs_dbhost.'/'.$this->dbs_dbnam;
    if(!empty($this->dbs_user) && !empty($this->dbs_dbhost) && !empty($this->dbs_dbnam)){
        $this->db_slave = $this->load->database($dsn, TRUE);
    }
}

Every thing is working fine, but problem is it take very long time in establishing slave database connect.

Any help will be appreciated.

IMHO, rather than use the getdbconfig at the model level, you should be considering using at the Data access layer level. Did you check out the connection from the connection pools. You can consider increasing the connection pool recycling frequency. Also, you should not be handling two connections at any point of time.

Post your details here for more detailed discussion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM