J
J
JackShcherbakov2018-02-05 10:38:33
PHP
JackShcherbakov, 2018-02-05 10:38:33

Why can't I set session.gc_maxlifetime?

Hello!
Here is part of the configuration:

session.auto_start = 1
session.gc_probability = 100
session.gc_divisor = 1
session.gc_maxlifetime = 100

That is, sessions should be cleared with a frequency of 1 second with a 100% probability
Here is the code:
<?php 
//ini_set("session.gc_probability", '100');
//ini_set("session.gc_maxlifetime", '2');
//session_start();

if(isset($_SESSION["count"])){
  $_SESSION["count"]++;
}else{
  $_SESSION["count"] = 1;
}
print $_SESSION["count"] . "<br>";
print $_COOKIE["PHPSESSID"];
?>

I refresh the page every 5 seconds (the session should be cleared at this time), and for some reason the session is still alive! It's only been 5 seconds! And for some reason the counter is incremented! What am I doing wrong?
At me it turns out that session dies only if to close the browser.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-02-05
@JackShcherbakov

If the session is still being accessed, it means that someone still needs it. Since someone needs it - why should it be removed?
https://github.com/php/php-src/blob/PHP-7.2.2/ext/...

P
Puma Thailand, 2018-02-05
@opium

Garbage collector how do you run it? No way, and you think that he will magically clean the sessions for you once a second?
Your option only says that if the session is older, then you need to clear it, and when the garbage collector passes there, you don’t set it in any way, maybe it will clean it tomorrow.
Write a program that just cleans sessions by hand once a second

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question