[Yii Framework] Share the session with memcache in Yii


When developing distributed applications with Yii, naturally, we will face that we have to 

share the session in different machine. So here we will use memcache to do it. 

here is the example to store the session with memcache in Yii, in the main.php file: 

         'cache'=> array(
            'class'=>'system.caching.CMemCache',
            'servers'=> array(
                 array(
                    'host'=>'192.168.1.1',
                    'port'=>11211,
                ),
            ),
         ),
         'sessionCache'=> array(
            'class'=>'system.caching.CMemCache',
            'servers'=> array(
                 array(
                    'host'=>'192.168.1.2',
                    'port'=>11211,
                ),
            ),
        ),
        'session' =>  array (
            'class'=> 'CCacheHttpSession',
            'autoStart' =>  true,
            'cacheID' => 'sessionCache',  // we only use the sessionCache to store the session
            'cookieMode' => 'only',
            'timeout' => 1400
        ),

For the details, pls refer to http://www.yiiframework.com/doc/api/1.1/CCacheHttpSession#cacheID-detail
 

Have fun with Yii! 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM