When the session count starts session.gc_maxlifetime

When loading each page, I run session_start() to resume the current session. When does the session.gc_maxlifetime countdown begin? Is session_start() called for the first time and is this session cookie set? Or does the timer restart every session_start() ?

When setting session.gc_maxlifetime for about 24 minutes, when on this timeline, session data will be collected in the garbage collection

  1. 12:00:00 First page load, session_start(), session cookie created 2. 12:10:00 page load, session_start() 3. 12:26:00 page load, session_start() 4. 12:55:00 page load, session_start() 

If the timer starts when the first page of session_start() loaded, I would expect it to collect garbage when loading 3. But if it resets every session_start() , then it will not be collected before loading 4.

I hope this is the last one, because then I could do javascript heartbeat every few minutes to call the page with session_start() .

If this is the first, session.gc_maxlifetime starts counting from the moment the session cookie was created, do I need to destroy / recreate or regenerate the id to reset count?

+8
php session
source share
1 answer

This is from the last call to session_start () OR / AND the last time it was recorded. My guess would be the last one, as it would change the β€œlast change” timestamp that the PHP garbage collector collected to determine whether it should be deleted or not. In this case, it starts counting from the last script to the end, which uses session_start (), or which explicitly ends the middle of the script with it, calling session_ write_ close ().

PS This would make the "heartbeat" beautiful and simple (in one line): http://prototypejs.org/api/ajax/periodicalUpdater

+2
source share

All Articles