[Solar-talk] Re-introducing Solar_Session with adapter support
Antti Holvikari
anttih at gmail.com
Sat Mar 1 18:46:27 CST 2008
On Sun, Mar 2, 2008 at 12:29 AM, Leo Chiao <leo.chiao at gmail.com> wrote:
> Just a few things I noticed on your Solar_Session_Adapter_Sql. When
> updating an existing record in _write, you aren't updating the datetime
> column that the garbage collector depends on. This means that the session
> will never live longer than the default timespan. I would suggest adding a
> modified_col which is used in both the _gc and _write functions. When
> updating an existing session, modified_col would get updated and _gc would
> look at the modified_col rather than the created_col. You could just use one
> datetime column, but some people may want to know the create date and
> compare it to the modified date to see how long someone's session has been
> in use.
>
> Another issue, which is common people when implement database backed
> sessions is that the _read method should be periodically updating the
> modified_date. In the scenario where someone is browsing a site with a
> session that is never writing/updating their existing session data (say
> someone browsing an online store, but never adding something to their cart),
> their session will get inadvertently garbage collected even when they are
> actively browsing the site. The way PHP file based sessions work is that
> the file timestamp is updated when the file is read which most people
> overlook. For performance issues, you probably wouldn't want to emulate
> that exact behavior and update on ever single read, but it is something to
> be aware of.
Very good points! It seems we need to update some sort of modified col
for the GC to work properly.
> You may want to also add session_write_close() via a __destruct or using
> register_shutdown_function for the db backed sessions
The only time when write() didn't get called for me was when I
redirected via header('Location: bah'). Solar calls
session_write_close() within Solar_Controller_Page::redirect(), so
that problem is at least somewhat solved there. Do you know of other
situations where write() would not get called by PHP? I mean, PHP
*should* almost always call write() when it shuts down, right? If
_destruct() gets called, why wouldn't write() get called right after
that?
Thank you very much for these excellent points.
--
Antti Holvikari <http://anttih.com>
More information about the Solar-talk
mailing list