[support] how to shrink sessions table

Jeremy Andrews lists at kerneltrap.org
Thu Jul 13 17:21:57 UTC 2006


On Thu, 13 Jul 2006 10:50:02 -0600
Laura Scott <laura at pingv.com> wrote:

> We have one site that is on the busy side and the sessions
> table is getting, shall we say, on the largish side (303k
> records). I'm looking at reducing that. I'm assuming this
> would be done in settings.php.

Out of curiousity, what problems are you experiencing from
your large sessions table?  That is, what is prompting you to
want to reduce the size of this table?  I've had the table
get more than ten times that size without experiencing any
problems.
 
> ini_set('session.cache_expire',     200000);
> ini_set('session.cache_limiter',    'none');
> ini_set('session.cookie_lifetime',  2000000);
> ini_set('session.gc_maxlifetime',   200000);
> 
> 
> My question: Which of these settings should we cut down to
> reduce the number of records? (We don't want to log people
> out upon closing the browser, so that approach is out.)
> 
> Would I cut down the cookie_lifetime?

There's a comment in session.inc that may help:
  // Be sure to adjust 'php_value session.gc_maxlifetime' to
  // a large enough value. For example, if you want user
  // sessions to stay in your database for three weeks before
  // deleting them, you need to set gc_maxlifetime to
  // '1814400'. At that value, only after a user doesn't log
  // in after three weeks (1814400 seconds) will his/her
  // session be removed.

In your case, you could make gc_maxlifetime smaller which
will cause sess_gc() to delete unused sessions quicker...

Cheers,
 -Jeremy



More information about the support mailing list