Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memcache, Mongodb or other Database storage for Lithium Sessions

Tags:

lithium

I'm getting comfortable with the Lithium framework, and was wondering if there were any samples for using MongoDB or Memcache for Lithium Sessions. Would there need to be a new Session Adapter written?

like image 210
Eric C Avatar asked May 03 '12 23:05

Eric C


2 Answers

One option is to set the session adapter to 'Php' in lithium and pass 'session.save_handler' => 'memcached' to the config options which will use the memcached extension's save handler to store sessions in memcache:

Session::config(array(
    'default' => array(
        'adapter' => 'Php',
        'session.save_handler' => 'memcached',
        'session.save_path' => 'sess1:11211, sess2:11211'
    )
));

http://php.net/manual/en/memcached.sessions.php

I store sessions in MongoDb by using the 'Model' adapter (which is available on lab.lithify.me):

Session::config(array(
    'default' => array(
        'adapter' => 'Model',
        'model' => 'app\models\Sessions',
        'name' => 'session'
    )
));

http://lab.lithify.me/lab/extensions/view/a68f6ad626aaf7be37805f8e72f672e2

like image 178
rmarscher Avatar answered Nov 05 '22 17:11

rmarscher


New adapters must be written for those:

  • https://github.com/UnionOfRAD/lithium/tree/master/storage/session/adapter
  • http://li3.me/docs/lithium/storage/session/adapter

Unless you keep using the PHP adapter and leverage session_set_save_handler which just got better in PHP 5.4.

I'd go with the second solution.

like image 3
greut Avatar answered Nov 05 '22 16:11

greut