[Solar-talk] Re-introducing Solar_Session with adapter support
Antti Holvikari
anttih at gmail.com
Sat Mar 1 15:42:18 CST 2008
I thought I'd tell you a bit about the session package I've been
working on. I'd be happy to hear opinions / comments.
Solar doesn't have an adapter-aware session package at the moment,
this tries to solve that problem. I have written 3 adapters:
* `Solar_Session_Adapter_File`: Uses the default PHP session save
handler 'files'. Nothing special about it. It's the same as not
setting any save handler.
* `S_S_Adapter_Memcache`: Uses the C-based 'memcache' save handler.
This basicly just says
`ini_set('session.save_handler', 'memcache');`
...but it also wraps the memcache server configuration into Solar
config keys.
* `S_S_Adapter_Sql`: Uses `Solar_Sql` for storing session data. You
can configure it with these keys (key => default value):
* 'table' => 'sessions',
* 'created_col' => 'created',
* 'sessid_col' => 'sessid',
* 'data_col' => 'data',
This adapter also knows how to garbage-collect old session data.
All of the adapters that use `session_set_save_handler()` internally,
will only write data if it has been changed since the last read. This
prevents many unneccessary writes.
Also, I think I've found a solution for the "remember me" feature
everybody wants to have. I've written a consept session adapter
(`S_S_Adapter_Remember`) that does exactly this. It uses a _setup()
hook which I've added to the abstract adapter class. In it, it checks
for a POST variable `remember`, and if it is set, it changes the
cookie lifetime to have a much bigger value (one week). A new cookie
will be sent with the new params if `Solar_Auth` sees a login attempt
and calls `session_regenerate_id()`.
The `_setup()` hook is really useful for running code that, for
example, manipulates the cookie parameters dynamically right before
the session starts.
Now onto the actual session data storage API.
At the moment `Solar_Session` is being used for session storage. And
now that my package replaces `Solar_Session` with the save handler
code we need something for saving stuff in $_SESSION. For this, I've
added a class `Solar_Session_Store`, which replaces the old
`Solar_Session` as it is. The purpose of this class is to divide
`$_SESSION` into segments so that keys won't collide and to provide an
API for one-time flashes. This class has exactly the same API as the
current `Solar_Session` class and so the only change that needs to be
made in Solar is to replace uses of `Solar_Session` with
`Solar_Session_Store`.
You can browse the code here:
http://git.anttih.com/?p=antti/solar.git;a=tree;f=Solar/Session
Paul, I will add this to trac as a feature request like you askes (not
this long though :-).
--
Antti Holvikari <http://anttih.com>
More information about the Solar-talk
mailing list