Re: Can session.save_path data be saved to a database instead of a file system?
| From: | Torsten Roehr | Date: | Wed, 02 Jun 2004 17:53:00 +0000 |
| Subject: | Re: Can session.save_path data be saved to a database instead of a file system? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187467@lists.php.net to get a copy of this message | ||
"Caleb Walker" <cwsupport@allconnected.net> wrote in message
news:pan.2004.06.02.15.21.57.73477@allconnected.net...
> On Wed, 02 Jun 2004 10:29:31 +0100, Michael Nolan wrote:
>
> > Caleb Walker wrote:
> >
> >> I have 2 servers fail-over/load-balanced behind an F5
> >> bigIP. I want session data to be maintained in the event one server
takes
> >> a dive. In this scenario, if a user is in the middle of doing
> >> something while logged in, they will not have to lose all work and log
> >> back into the server to continue working. Can that be done without
> >> rewriting an application?
> >> I saw a link here:
> >>
http://www.phpfreaks.com/quickcode/DB_eSession_class_securely_stores_PHP_ses
sions_in_a_MySQL_DB/286.php
> >> but this seems to be something that would have to be written into the
> >> application and I didn't write it and do not want to take on the
> >> responsibility to do so from here. Any thoughts would be much
appreciated.
> >>
> >> Thank You,
> >> Caleb
> >>
> >
> >
> > Yes, you can use a database to store session data and retain existing
> > session manipulation methods. Surprisingly, the PHP manual tells you
how:
> >
> >
> > http://uk.php.net/manual/en/function.session-set-save-handler.php
> >
> > And lists a couple of examples, including this one at Zend:
> >
> > http://www.zend.com/zend/spotlight/code-gallery-wade8.php
> >
> > Mike
>
> This looks like modifications that need to be made to the application. I
> dont really want to touch the application. Instead I just want PHP,
> through the php.ini file or whatever to take the session data and put it
> in a database instead of the file system. In doing it this way, I assume
> that I will not have to touch somebody else's code.
>
> Thanks for the response.
It's pretty simple. I'm using PEAR's HTTP_Session in combination with
PEAR::DB:
http://pear.php.net/package/DB
http://pear.php.net/package/HTTP_Session
Just set those two packages up, create a session table (see
HTTP_Session/Container/DB.php for the schema) and set this HTTP_Session
option:
HTTP_Session::setContainer('DB', array('dsn' => $dsn, 'table' =>
'sessions',
'autooptimize' => true));
...and off you go.
Ideally you should change the lines where the session variables are set and
get to use HTTP_Sessions static methods instead. But this shouldn't be much
of a problem. It could even work without these changes by directly accessing
$_SESSION.
Bets regards, Torsten Roehr