Re: [phplib] Garbage Collection/Sessions From: Michael Chaney (mdchaney <email protected>)
Date: 10/03/00

> >The proper way to clean it out, especially for a large site, is to write
a
> >[gasp] Perl script that runs as a cron job every 15 or 30 minutes. It'll
> >only be a few lines. Actually, you can do it with a single MySQL
> statement,
> >but it will differ for other RDBMS products since the date functions tend
> to
> >differ among them.
>
> I had thought about this. something like
>
> DELETE FROM active_sessions WHERE changed < $time
>
> and just set $time to be an hour ago?

Yeah, basically that's it. Note that "changed" is a varchar, so you have to
get the time into the correct format.

date_format(now()- interval 1 hour,'%Y%m%d%H%i%S')

That does it. Note that this only works in MySQL. Date functions tend to
differ greatly across various RDBMS implementations.

> Is this how you handle the problem? Have you noticed these sessions
hurting
> your site's performance at all?

I don't think it hurts performance too badly, since sid+name is a primary
key on active_sessions. But it can only help to keep the row count down to
a reasonable level.

The site that I mentioned in my message, www.patsgold.com, has thousands of
rows in there (there are 11,604 in there now). Yet a typical day has no
more than 5000 page views. The average session has four page views, so
there should be around 1200 sessions going through that table on a given
day, probably no more than 500 sessions in the active_sessions table at any
given time.

I would recommend that you run this every 15 minutes, and set gc_probability
to 0 in your local.inc.

delete from active_sessions where
   changed<date_format(now() - interval 1 hour,'%Y%m%d%H%i%S');

Replace the "1" with however many hours you have yours set to.

Michael

--
Michael Darrin Chaney
mdchaney <email protected>
http://www.michaelchaney.com

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>