Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Does Phalcon supports persistent DB connection?

Hi. My question is about connection pooling.

Does Phalcon natively supports DB connection pooling? Or: Can I create persistent DB connection like in mysql: mysql_pconect() (or with "p:" prefix in hostname)?



419
Accepted
answer
edited Oct '14

You can make phalcon to create persistent DB connections when setting up the DB service with settings array like this:

app/config/config.ini

[database]
username        = myuser
password        = mypassword
dbname          = mydb
host            = 127.0.0.1
persistent      = true
encoding        = UTF8

public/index.php

  $config = new Phalcon\Config\Adapter\Ini(__DIR__ . '/../app/config/config.ini');

(...)

    //Set the database service
    $di->set('db', function() use ($config){
        return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
            "host"      => $config->database->host,
            "username"  => $config->database->username,
            "password"  => $config->database->password,
            "dbname"    => $config->database->dbname,
            "charset"   => $config->database->encoding,
            "persistent"=> $config->database->persistent
        ));
    });


23.9k

Thank you! I did not find it in the API docs...



23.9k

Yeah, I need to re-read docs now... I read full docs for Phalcon a year ago, after - only changelogs :)