Session database handler (great for load-balancing)

Your code modifications and patches you want to share with others.
Locked
gharding
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 173
Joined: Thu Aug 18, 2005 8:23 pm
Location: New York, NY

Session database handler (great for load-balancing)

Post by gharding » Fri Nov 18, 2005 1:29 am

I load-balance Joomla across 3 webservers and would commonly run into getting logged out due to my load-balancer deciding I would visit the server that didn't have my session file.  Annoying, right?  Sure is.  Well, I fixed my problem by creating persistent connections through the load-balancer.  But for those of you who don't have that luxury (like being hosted on SourceForge, I believe), I've created a session handler that stores all sessions in the database.  I wouldn't quite call this stable because I've only been able to test it on my development servers (the garbage collector may be iffy, if anything.)  I've attached the file and included the edit you need to make and the table structure.

Please note that will probably have worse performance than PHP's built-in session handling, so I'd only advise this solution for people who need it.  This can be useful for load-balanced setups or installations that do not have write permissions on the filesystem.  If your current setup is working fine with PHP's built-in sessions, don't waste your time installing this.

Database structure:
REPLACE #_ WITH YOUR TABLE PREFIX (jos or mos, commonly)!!!

Code: Select all

CREATE TABLE `#__sessions` (
 `id` varchar(40) NOT NULL,
 `time` TIMESTAMP NOT NULL DEFAULT NOW(),
 `data` text NOT NULL,
 PRIMARY KEY  (`id`)
 ) TYPE=MyISAM;
Insert this line into joomla.php

Code: Select all

require_once( $mosConfig_absolute_path . '/includes/session_handler.php'); //hack by gharding[@gmail.com]
after this code (should be after line 82):

Code: Select all

require_once( $mosConfig_absolute_path . '/includes/version.php' );
require_once( $mosConfig_absolute_path . '/includes/database.php' );
require_once( $mosConfig_absolute_path . '/includes/gacl.class.php' );
require_once( $mosConfig_absolute_path . '/includes/gacl_api.class.php' );
require_once( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php' );
require_once( $mosConfig_absolute_path . '/includes/joomla.xml.php' );
require_once( $mosConfig_absolute_path . '/includes/phpInputFilter/class.inputfilter.php' );

Upload session_handler.php to /includes/session_handler.php

Good luck.  Please email/pm/reply with feedback!
You do not have the required permissions to view the files attached to this post.
Last edited by gharding on Fri Nov 18, 2005 3:37 am, edited 1 time in total.

User avatar
pergolesi
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Sep 14, 2005 6:18 am
Location: Lofoten - Norway
Contact:

Re: Session database handler (great for load-balancing)

Post by pergolesi » Tue Jan 31, 2006 11:58 am

Where are the answers to this post? This looks like a nice solution to increase the performance of Joomla.  Have anybody tried this?

gharding
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 173
Joined: Thu Aug 18, 2005 8:23 pm
Location: New York, NY

Re: Session database handler (great for load-balancing)

Post by gharding » Tue Jan 31, 2006 11:15 pm

I imagine it's actually worse for performance (more queries = more time), but useful if you're not totally maxing out your resources.  I submitted a feature request with this and I think they said Joomla would provide a little framework for stuff like that, so I guess it's going to wait (understandable, as who wants to add kludge when you're working to remove it?)

Milchi
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Sat Nov 05, 2005 7:16 pm

Re: Session database handler (great for load-balancing)

Post by Milchi » Thu Feb 01, 2007 5:02 pm

gharding wrote: I imagine it's actually worse for performance (more queries = more time), but useful if you're not totally maxing out your resources.  I submitted a feature request with this and I think they said Joomla would provide a little framework for stuff like that, so I guess it's going to wait (understandable, as who wants to add kludge when you're working to remove it?)
NICE! And Powerful. Its only used in my Backend (frontend is no problem in load balancing scenarios). But backend now FINALLY works after 9 months of searching a solution

gharding
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 173
Joined: Thu Aug 18, 2005 8:23 pm
Location: New York, NY

Re: Session database handler (great for load-balancing)

Post by gharding » Thu Feb 01, 2007 5:33 pm

Looks like this (or something similar) is making it into 1.5:

http://forge.joomla.org/sf/go/artf2179

jawatkin
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri May 04, 2007 1:54 pm

Re: Session database handler (great for load-balancing)

Post by jawatkin » Wed Jan 09, 2008 8:32 pm

Sorry to dig up an old topic, but I've tried this on 1.0.13 and can't get it to work.  If I remove the "include" from joomla.php, I'll get bounced out of the backend as soon as my webserver (lighttpd) decides I should be served by a different PHP backend.  If I add the "include" into joomla.php, it just bounces me out directly on login.  I've checked the "jos_sessions" table after trying to log in and there are no entries, so it appears that they aren't being stored.

Anyone have any luck on 1.0.13?

Milchi
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Sat Nov 05, 2005 7:16 pm

Re: Session database handler (great for load-balancing)

Post by Milchi » Wed Jan 09, 2008 8:49 pm

jawatkin wrote: Sorry to dig up an old topic, but I've tried this on 1.0.13 and can't get it to work.  If I remove the "include" from joomla.php, I'll get bounced out of the backend as soon as my webserver (lighttpd) decides I should be served by a different PHP backend.  If I add the "include" into joomla.php, it just bounces me out directly on login.  I've checked the "jos_sessions" table after trying to log in and there are no entries, so it appears that they aren't being stored.

Anyone have any luck on 1.0.13?
This was written for the Old Joomla System, it is NOT FUNCTIONAL in the New System since 1.0.x. I wrote the author but he has nothing to do with joomla anymore, so no new version is coming up from him.

jawatkin
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri May 04, 2007 1:54 pm

Re: Session database handler (great for load-balancing)

Post by jawatkin » Thu Jan 10, 2008 9:59 pm

Milchi wrote: This was written for the Old Joomla System, it is NOT FUNCTIONAL in the New System since 1.0.x. I wrote the author but he has nothing to do with joomla anymore, so no new version is coming up from him.
Thanks for the info.  Any other solutions (other than going to 1.5, which I've been told fixes this... it does right?)?


Locked

Return to “Core Hacks and Patches”