I can think of several different ways, each with their own pros and
cons.  Instead of thinking in terms of when a Session *has timed out*,
think in terms of when a Session *will time out*.

1. Update your DB with the current time {NOW()} plus your session
timeout length every time the user hits a page.  (In your
Application.cfm, presumably.)  This has the benefit of being completely
stateless and absurdly easy to implement, with the drawback that you've
just added a DB hit to every single page hit.  If you ever do real-time
reporting, you probably want to change any future times to "Currently
Logged In" or somesuch, lest you beget confused managers.  If you
provide a manual logout facility you can update the db with the correct
time.

2. Following the first idea, keep a cache of all Sessions in your
Application scope {Struct:Application.Sessions[UserID]}.  In this, keep
the last time each person hit a page.  Everyone once in a while, loop
through the struct and prune anything older than the session timeout
length and update your db.  You can have a scheduled script handle the
pruning, or set an App variable that contains the next time it should
happen and the user unlucky enough to hit a page right then gets the
extra half-second overhead while you prune.  (Nice if your ISP frowns on
CFSchedule, but a bit tricker to program as you'll need a mutex or
you'll block every user.)  Pros include far fewer db hits (only adding
one per session), but cons include trickier programming (lock, lock,
lock!), occasional page slowdowns for pruning, missing data if you have
a server reboot, and higher memory over head.  If you provide a manual
logout facility you will need to prune appropriately.

You can also mix and match a bit to tweak your pros and cons.  (Update
the db for each user every 5 minutes or 10 pages even if they haven't
timed out, in case your server hiccoughs frequently.)

HTH,
-R


-----Original Message-----
From: Greg Jordan [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, April 09, 2002 16:14
To: CF-Talk
Subject: record session timeout


We have a login app on our intranet which creates a session and records
the time/date it was created.  Besides using a logout app to record when
the session is ended/deleted by the user, is it possible to record when
a session is timed out?

Thanks

Greg

---
[This E-mail scanned for viruses by Declude Virus]


______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to