1

I have put:

php_value session.gc_maxlifetime 1

in my .htaccess file so my PHP Sessions should expire after 1 second but they are not.

I set a session and its still set after a few hours.

If i look at phpinfo() the session.gc_maxlifetime is set to 1 on the local value

any ideas why this is not working

  • 1
    the maxlifetime only applies when the garbage collector actually kicks in. You need to modify the gc_probability and gc_divisor settings as well, so the GC will kick in more frequently. default config is 1/100, meaning that's a 1% chance of a GC run being performed. – Marc B Nov 08 '13 at 16:40
  • what do i need to change those to? –  Nov 08 '13 at 16:49
  • whatever probability you want the GC to run at. For development, go with 1/1, but do NOT forget to change it back to something more reasonable, otherwise you're going to be going all Godzilla on your sessions. – Marc B Nov 08 '13 at 16:52

1 Answers1

0

As the php manual says:

session.gc_maxlifetime integer :

session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

Note: If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.

session.gc_probability integer:

session.gc_probability in conjunction with session.gc_divisor is used to manage probability that the gc (garbage collection) routine is started. Defaults to 1. See session.gc_divisor for details. session.gc_divisor integer

session.gc_divisor:

coupled with session.gc_probability defines the probability that the gc (garbage collection) process is started on every session initialization. The probability is calculated by using gc_probability/gc_divisor, e.g. 1/100 means there is a 1% chance that the GC process starts on each request. session.gc_divisor defaults to 100.

You also can refer this post.

Community
  • 1
  • 1
LF00
  • 27,015
  • 29
  • 156
  • 295