[ic] moving sessions to mysql - no luck

Jonathon Sim sim at zeald.com
Sat Jan 26 02:18:43 EST 2008

DB wrote:
> But before I go away, does anyone have a suggestions for keeping the 
> sessions table from growing without bound? How old is too old for a 
> session?
Make a shell script in /etc/cron.daily that does this:
mysql -u youruser --password=yourpassword -h yourdatabase server -e 
'DELETE FROM session_mysql WHERE (last_accessed + INTERVAL 7 DAY) < NOW()'

(disclaimer, haven't tested the script, we have a perl script that's way 
more complicated than this,  but thats the query we run)

7 days is a long time but allows for some debugging of old sessions.  
Otherwise 1 day is plenty (it only has to be greater than the expiretime 
on your sessions)

Another note:  Either use myisam as the table type, or if using innodb 
turn off the primary key on code (make it a unique index instead).  
Innodb is very slow when using random primary keys (which I found out 
the hard way over the christmas rush :-/  )

Jonathon Sim <sim at zeald.com>
Senior Developer @ Zeald.com (http://www.zeald.com)

More information about the interchange-users mailing list