Page 1 of 1

Sessions being dropped

Posted: Mon Mar 24, 2008 8:06 pm
by dhampson
So, I've created a small piece of software for a business. It's only used on our internal network, so security is no /too/ big an issue. Never-the-less, I have people log in with a password, because each person has several students, and no one has access to each others student.

I simple use this to create my sessions:

Code: Select all

   
    session_name("Company-DB");
    session_start();
 
Passwords are stored in the $_SESSION array.

This has worked fine, but every once in a while, it will fail to connect to the mysql data base. This means any work is lost, and you need to start the whole thing over again. This seems to happen after a bit of inactivity. However, if you open another browser window and visit other sites, it can drop your session after just a few minutes. This only occurs once a week or so, but can be very annoying when it does. It happens with Safari, IE, and Firefox.

Would creating a time limit prevent this from happening? Would modifying the .ini file help? If so, how?

Any help or comments would be appreciated.

--Dave

Re: Sessions being dropped

Posted: Mon Mar 24, 2008 10:56 pm
by flying_circus
How long of a period of inactivity? Sessions have a lifetime.

Re: Sessions being dropped

Posted: Tue Mar 25, 2008 4:28 pm
by dhampson
Sessions are being dropped after a period of inactivity ranging from 15 minutes to 3 hours. It's a probability thing. If I left a browser window open overnight, I can guarantee that the session will be dropped. If I visit others web sites, it increases the probability of sessions being dropped sooner.

I did not declare a time limit when creating a session, because it's my understanding that the session is supposed to last until the browser window is closed this way. I don't want to create a time limit, unless I also create a javascript timer to alert users that time is running out. It is a very chaotic environment, and sometimes we have to leave our computers for a few hours. An alert could just be ignored.

Anyway, and thoughts as to why session are being dropped -before- the window is closed?

Re: Sessions being dropped

Posted: Tue Mar 25, 2008 4:56 pm
by flying_circus
Session lifetime is not really based on the length that the window is open. Since it is a server side thing, the lifetime starts dying once the last time you've accessed a page on your site. If you're running a stock setup, the session gets stored as a text file, and then marked as garbage after so long of inactivity. You can change those settings in your php.ini under the [sessions] heading.

If you want them to last longer, you should be able to modify the php.ini to do what you need, otherwise, you can implement your own session handler using the session_set_save_handler() function.

http://us.php.net/manual/en/function.se ... andler.php

Re: Sessions being dropped

Posted: Sun Mar 30, 2008 3:53 pm
by dhampson
Thanks Mr. Circus. 8) I'll try modifying the php.ini file.

I am also upgrading the server as well. It's an old AMD, and the Linux kernel in it has a small bug that fails to keep track of time on the AMD processors. Every week or so I manually reset the internal clock because it's about 90 minutes fast. I don't see how that could effect things, but you never know.........

--Dave

Re: Sessions being dropped

Posted: Fri Apr 11, 2008 5:48 pm
by dhampson
Session lifetime is not really based on the length that the window is open. Since it is a server side thing, the lifetime starts dying once the last time you've accessed a page on your site. If you're running a stock setup, the session gets stored as a text file, and then marked as garbage after so long of inactivity. You can change those settings in your php.ini under the [sessions] heading.
OK. The variable I think needs to be changed is session.gc_maxlifetime. Is this correct?

--Dave

(I upgraded to Ubuntu 7, and the new kernel has the AMD-clock bug fixed. I thought that might alleviate the problem, but alas, it now times out quicker.)

Re: Sessions being dropped

Posted: Fri Apr 11, 2008 5:57 pm
by s.dot
dhampson wrote:OK. The variable I think needs to be changed is session.gc_maxlifetime. Is this correct?
Yup. It's value is in seconds. So to make it 3 hours.. 60*60*3 = 10800.

I think the default is 1440 which is 24 minutes.