Sessions garbage collection (memcache + MySQL used)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PROM
Forum Newbie
Posts: 1
Joined: Thu Jan 08, 2009 3:42 pm

Sessions garbage collection (memcache + MySQL used)

Post by PROM »

Hi guys, I need some help with the php sessions.
I'm using standard PHP Sessions with memcached (and I don't want to store them in the DB) but I also keep some logging history in the DB. When a user logs in I record his session ID and the time he logged in. I also add the time he logged out later. The problem that I have is with expired sessions. I want to write my own cron job to destroy unactive sessions and store the time the user was last active in the DB to keep the log full.

I tried a couple of things but none of them worked .... to start the sessions in the cron by ID and destroy them (finally I realized that should not be done). I thought of deleting the session files .... but I'm using memcached and I weren't able to figure out the keys it uses to store the sessions in the cahce - so I'm not able to delete them. The other problem is that I keep the last page load in $_SESSION['last_activity'] nut is there any way for the server to read what's inside the session?

Kinda mess in my head with this sessions right now ... I never used custom sessions before. I also thought of using session_set_save_handler but it seems too complex to me. In fact the only thing that I need is a way to delete old sessions by my own - nothing else - this will solve all my problems

Any ideas? Thanks in advance!
Post Reply