cleanup of server side session files..

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
scints
Forum Newbie
Posts: 3
Joined: Tue Mar 25, 2003 11:37 am

cleanup of server side session files..

Post by scints »

i saw one new session file appear each time i use a new IE to open my php which uses session, and those session files remains there even IE close. How to clean them up automatically?
User avatar
musashi
Forum Commoner
Posts: 39
Joined: Tue Jul 23, 2002 12:51 pm
Location: Santa Cruz - CA

cleaning session files

Post by musashi »

I am assuming you are referring to the session files in the /tmp directory (if you are on a unix system. Not sure where they are on windows).

Anyway, those files are cleaned up by the session_gc (the garbage collection routine). If you didn't modify this routine (by making a customized session handler) then PHP will take care of the clean up for you. If you don't see the files disappear after a while you might want to check your php.ini file to insure that the gc has a short max_lifetime (default is 1440 in seconds). And that the gc_probability is set to something fairly high (default is 1, which is in percentages so 1 = 100%, 0.9 = 90%, etc.)

If you really want to work at it you can delete the files by hand with your own function, or you can customize the session handling and make your own gc function. It all depends on what you are trying to do. If there is sensitive information, you might consider this, or encrypting the session file data (something like mcrypt with the $_SESSION var contents).

:wink:
Post Reply