Session time

<?php echo ini_get("session.gc_maxlifetime"); ?>

The output of the code above is ‘1440’.
Does it mean that keeping time of any sessions in the server is 24 minutes?
or
Does it mean that keeping time of any sessions in the server is 24 hours?

Google and the PHP documentation are your friends

http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime

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).

So yes, but not exactly. depending

So you mean that keeping time of any sessions in the server is 24 minutes instead of 24 hours.
Am I right?

I guess both minutes and hours having increments of 60 could be a bit confusing.
But yes, 1440 divided by 60 (seconds to minutes) gives 24 minutes,

Seconds in a day would be 60 x 60 x 24 = 86400

Note that because of session.gc_probability and session.gc_divisor it likely will not be exactly 24 minutes

<?php echo ini_get("session.gc_maxlifetime").'<br>'; echo ini_get("session.gc_probability").'<br>'; echo ini_get("session.gc_divisor").'<br>';
The code above produces the following result.

1440 1 100
I guess it means “session.gc_maxlifetime” of the server is ‘1440’.
I guess it means “session.gc_probability” of the server is ‘1’.
I guess it means “session.gc_divisor” of the server is ‘100’.

What does “session.gc_probability is 1” mean?
What does “session.gc_divisor is 100” mean?

If “session.gc_maxlifetime is 1440”, “session.gc_probability is 1” and “session.gc_divisor is 100”,
does it mean “keeping session time is 24 minutes or 24 hours”?

No, as stated in the PHP documentation I linked to, it means

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.

My take is that 1% is low, but depending on how often a SESSION is started the odds are higher. that a SESSION will be GC’d

Not as clear cut as Java GC but maybe a bit more than JavaScript GC

if I want every session keeps 1 hour(3,600 seconds), what should I do?

(I like to control keeping time of the session)

In that case I wouldn’t rely on GC to do that.

SESSION variables are global so they can be both created and destroyed via script.

Maintaining control would require a bit more resource use. eg.
When a SESSION is created you could enter a “value and time” into a database table and at the same time destroy older SESSIONs and delete that row from the table.

[quote]you could enter a “value and time” into a database table and at the same time destroy older SESSIONs and delete that row from the table.[/quote]I have to think deeply it. Thank you very much, Mittineague.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.