Memcache, Mongodb or other Database storage for Lithium Sessions
-
05-06-2021 - |
Question
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?
Solution
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
OTHER TIPS
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.