Yii 1.1: session-storage-abstract

This extension contains different storage types where session data can be stored
2 followers

Yii 1.1 supports default php session handler (CHttpSession) and SQL database session storage (CDbHttpSession). So, this extension contains and interface that you can use to implement any type of session storage without rewriting of HttpSession component methods. Also you session storage will contain optional extra parameter of session - "userId", so you will be able to distinguish guests' sessions and authenticated users' sessions. Another problems which solves this extension described here (in can be very useful): http://blog.jviba.com/en/web/asynchronous-change-of-session-in-php

Requirements

e.g. Yii 1.1 or above

Usage

  1. Setup imports:
...
'import' => array(
    ...
    'ext.session.*',
    ...
),
...
  1. Change configuration of an application session component:

If you want to use SQL database as storage of sessions:

...
'components' => array(
    'session' => array(
        'class' => 'UserHttpSession',
        'storage' => array(
            'class' => 'SQLSessionStorage',
            'connectionID' => 'db',
        ),
    ),
    ...
    'db' => array(
        'class' => 'CDbConnection',
        ....
    ),
    ...
),
...

If you want to use MongoDb as storage of sessions you should download (http://www.yiiframework.com/extension/yiimongodbsuite"YiiMongoDbSuite extension") and install it into the application.

...
'components' => array(
    'session' => array(
        'class' => 'UserHttpSession',
        'storage' => array(
            'class' => 'MongoSessionStorage',
            'connectionID' => 'mongodb',
        ),
    ),
    ...
    'mongodb' => array(
        'class' => 'EMongoDB',
        'connectionString' => 'mongodb://localhost',
        'dbName' => 'mymongodatabasename',
        'fsyncFlag' => false,
        'safeFlag' => true,
        'useCursor' => false,
        ....
    ),
    ...
),
...

If you want to use Memcache as storage of sessions:

...
'components' => array(
    'session' => array(
        'class' => 'UserHttpSession',
        'storage' => array(
            'class' => 'MemcacheSessionStorage',
            'componentID' => 'memcache',
        ),
    ),
    ...
    'memcache' => array(
        'class' => 'CMemCache',
        ....
    ),
    ...
),
...

If you want to use Redis as storage of sessions you should download (https://github.com/phpnode/YiiRedis"YiiRedis extension") and install it into the application.

...
'components' => array(
    'session' => array(
        'class' => 'UserHttpSession',
        'storage' => array(
            'class' => 'RedisSessionStorage',
            'componentId' => 'redis',
        ),
    ),
    ...
    'redis' => array(
        'class' => 'ARedisConnection',
        ....
    ),
    ...
),
...

Resources

Problems which will solve this extension described here: http://blog.jviba.com/en/web/asynchronous-change-of-session-in-php

Be the first person to leave a comment

Please to leave your comment.

Create extension