Does Yii CDbConnection really work with persistent connection and $autoConnect=true?

I was just investigating persistent database connection and I came across this in PHP PDO documentation

The way Yii sets persistent connection is like so;




public function setPersistent($value)

{

    return $this->setAttribute(PDO::ATTR_PERSISTENT,$value);

}



Which in turns use the following.


 

public function setAttribute($name,$value)

{

   if($this->_pdo instanceof PDO)

      $this->_pdo->setAttribute($name,$value);

   else

      $this->_attributes[$name]=$value;

}



The connection is established like so using ‘$this->_attributes’ which will only get set for ATTR_PERSITENT if the PDO object was not created yet.




protected function createPdoInstance()

{

    $pdoClass='PDO';

    if(($pos=strpos($this->connectionString,':'))!==false)

    {

        $driver=strtolower(substr($this->connectionString,0,$pos));

        if($driver==='mssql' || $driver==='dblib')

            $pdoClass='CMssqlPdoAdapter';

    }

    return new $pdoClass($this->connectionString,$this->username,$this->password,$this->_attributes);

}



At this stage, I am inclined to draw the conclusion that CDbConnection does not support Persistent connection by default, one has to at least set autoConnect=false before trying to use persistent database connections.

If my conclusions are correct, it would be nice to document this somewhere, if so where?

… and this is the case when you add ‘persistent’=>true to your application configuration. When the configuration is applied, no PDO object existst, so _attributes is used.

Hmm… if that is the case, I am not able to achieve persistent connection. After revisiting my test case, it would seem autoConnect has nothing to do with it either <_<

I am using mysql SHOW PROCESSLIST to determine the number of connections. Has anybody had luck with this at all?

I guess you already know this, but for the interested reader, here’s more on persistent connections:

http://de3.php.net/manual/en/features.persistent-connections.php

Personally i’ve only had problems when enabling them on some apps and never observed any significant performance impact without them.

Sorry, but I got a little bit lost here. What is the conclusion of this discussion? is setting persistent to TRUE enough to have persistent connection to DB or setting autoConnect to FALSE is also necessary.

It’s enough to set persistent to true.

http://www.yiiframework.com/doc/api/1.1/CDbConnection#setAttribute-detail

// check the source code of that method