Garbage Collection in PHP session

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
saibot1
Forum Newbie
Posts: 8
Joined: Sat Nov 25, 2006 9:13 pm

Garbage Collection in PHP session

Post by saibot1 »

I'm tried to introduce Garbage Collection for my session files but php creates other session files that are not the ones I use; therefore garbage collection does not work. What php script can I write to achieve garbage collection through scripts ?
Last edited by saibot1 on Sat Dec 16, 2006 2:27 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please explain in more detail why you're trying to write what seems to be your own session data storage and why you do it this way.
Of course the session gc does not work with just arbitrary code. If you need your own session handler but want to use some parts of php session management have a read of http://de2.php.net/session_set_save_handler
saibot1
Forum Newbie
Posts: 8
Joined: Sat Nov 25, 2006 9:13 pm

Post by saibot1 »

By creating sessions that way I can know what person made that file and associate it with the person that made it if any problems occur.
Last edited by saibot1 on Sat Dec 16, 2006 2:28 pm, edited 2 times in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

saibot1 wrote:By creating sessions that way I can know what was the ip address of the person that made that file and associate it with the person that made it if any problems occur.
If this session information is anywhere near critical, I would suggest against using IP's as they can change or even be mocked.
saibot1 wrote:By using php.ini I was trying to use an easy way to do garbage collection but I think using regular scripts may be actually easier.
One or the other would be the best way to go, in my opinion. Either use PHP's sessions, or develop your own session handling from the ground up. It is not that hard to do, but you should consider your needs and why you want to do things the way you are doing them.

As another suggestion, can't you just use PHP's session handling to fetch your users IP and session that data in the session array?
Post Reply