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?
Asked
Active
Viewed 858 times
2 Answers
4
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

rmarscher
- 5,596
- 2
- 28
- 30
-
How to specify memcached only for production environment ? – Eno Sep 24 '12 at 19:58
3
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.
-
session_set_save_handler Does seem to be the better option at the moment. I assume it would be best to store that in \extensions and call it in the session bootstrap? – Eric C May 04 '12 at 16:13
-
You can create your own adapter into you app extensions which inherits from Php and sets the save handler accordingly to what you want. Maybe the folks on IRC can help you as well. – greut May 04 '12 at 16:46