Session Question

1 view
Skip to first unread message

Robert

unread,
Jul 2, 2008, 6:50:53 PM7/2/08
to zoop-users
My website is in development. It has a number of pages which require
user data from the database. The only thing the code is doing with
sessions (so far) is to remember the logged in user so that it can
access the data from postgresql for the different pages on the site.

Currently the code uses session::start() in index.php and when the
user logs in it invokes $_SESSION['personId'] = $id;
session::saveChangesUnsafe(); and session::destroy() when the user
logs off.

Zoop creates new records in both the session_base and session_data
tables in postgresql when the initial page is accessed and it updates
it with the users id when he logs in. It also deletes the records when
the user logs off and destroy() is invoked.

My questions: My tables are filling up with empty session_base and
session_data records from (1) going into and out of the initial web
page, and (2) from users who never log off. So two questions. How do I
invoke garbage collection on the postgresql database (session_base and
session_data) after that session data is no longer needed (browser
closes, etc)? How do I invoke a max-time limit to kill the session so
that it is eligible for garbage collection? (Or is there a different
way to expire sessions and garbage collect?)

Thanks.

Rick Gigger

unread,
Jul 3, 2008, 12:32:51 AM7/3/08
to zoop-...@googlegroups.com
On Jul 2, 2008, at 4:50 PM, Robert wrote:
>
> My questions: My tables are filling up with empty session_base and
> session_data records from (1) going into and out of the initial web
> page, and (2) from users who never log off. So two questions. How do I
> invoke garbage collection on the postgresql database (session_base and
> session_data) after that session data is no longer needed (browser
> closes, etc)? How do I invoke a max-time limit to kill the session so
> that it is eligible for garbage collection? (Or is there a different
> way to expire sessions and garbage collect?)

The zoop session handling is layered on top of the php session
handling. Every time a script closes that uses php sessions it uses a
probability function to determine whether or not to do garbage
collection. Here the the documentation for the relevant runtime
config options: http://us2.php.net/manual/en/
session.configuration.php. Especially look at session.gc_probability,
session.gc_divisor, session.gc_maxlifetime. The defaults give you a
1% chance that garbage collection will be invoked upon completion of
any given script and a timeout of 24 minutes. I'm pretty sure that
you can set any of those with init_set (http://us2.php.net/ini_set) so
you can change them on a per app basis instead of system wide if you
want.

If you are just testing you would likely build up a lot of sessions
before it invokes garbage collection. Try switching gc_probability/
gc_divisor to be the same (so a probability of 100%) and see if that
causes them to be cleaned up on every script. If not maybe there is a
problem with the my garbage collector. It should be working though.

Check out the very last method (gc) in this file: http://code.google.com/p/zoop/source/browse/trunk/framework/session/SessionDb.php
to see exactly how I am doing the garbage collection.

Thanks,

Rick

P.S. I am just getting into things again post-surgery so if there was
anything you asked before I may have lost track of it so feel free to
ask again.

RB Jackson

unread,
Jul 7, 2008, 7:38:09 PM7/7/08
to zoop-...@googlegroups.com
Hi Rick,

Thank you for your reply about session garbage collection.  I had seen your gc ( ) function.  What I did not realize, was that it was invoked by PHP -- in other words that it was on top of PHP gc. 

I changed session.gc_probability in php.ini to 50 so that I could check out the gc function.  Unfortunately, it is crashing on me from the zoop module.

I'm not sure if it is a zoop problem or if I have specified something incorrectly. However, the session handling on the writing to the database is working okay. Would you mind trying this URL? And see what you think?

http://znzn.us/dev2/

Thanks,

Robert

Rick Gigger

unread,
Jul 7, 2008, 9:17:11 PM7/7/08
to zoop-...@googlegroups.com
I just committed a change that should fix the problem.  Could you do an svn update on SessionDb.php let me know if it works for you now?

RB Jackson

unread,
Jul 8, 2008, 1:16:58 AM7/8/08
to zoop-...@googlegroups.com
Rick,

Sorry. It took me awhile. I was off doing something else and was not watching my email.

Also, in order to have a stable platform for development, I am using Zoop1.51.  So I wanted to double check the svn version to make sure that it would be compatible with 1.51.  I see that you changed only one line of code, so I assume that it is compatible.

I checked out the SessionDb.php module and replaced my old one.  It appeared to do odd things, like session_base and session_data getting out of synch, and sometimes not even creating a new session_base record when opening the site.  But I can't tell for sure.  I have attached a screenshot of my last attempt at entering the site.

You can try the site also.  http://znzn.us/dev2  I now have gc_probability set to 100.  It has the updated version of SessionDb.php

Thanks,

Robert
2008-07-07_230759.jpg

RB Jackson

unread,
Jul 8, 2008, 1:58:26 AM7/8/08
to zoop-...@googlegroups.com
Rick,

Also getting this error when I try to do a session_destroy ( ) function on logout.  This error happens with the new SessionDb.php update.  See attached.

I am going to set gc_probability back to 0 for a while.  My programmer needs to get some other work done, and he is under a tight deadline this week.

Robert
2008-07-07_235419.jpg
Reply all
Reply to author
Forward
0 new messages