0

My main objective is to get the count of currently active session. My code is -

$count = count(scandir(ini_get("session.save_path")));

But the value is increasing only. Th site may not have any active users. Why $count is not decreasing in that case?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • Likely because there are still expired session data files, that have not yet been cleaned up by the _garbage collector_. _“My main objective is to get the count of currently active session.”_ - the approach you have chosen, is not really suitable for that to begin with. – CBroe Jan 28 '21 at 12:33
  • https://stackoverflow.com/questions/54132603/removing-expired-sessions – Alive to die - Anant Jan 28 '21 at 12:34
  • What is the value of the session timeout timer session.gc_maxlifetime? – Mark Jan 28 '21 at 12:34
  • @Mark maxlifetime is 7200. – s.k.paul Jan 28 '21 at 12:43
  • Ok, so the garbage collector should delete them after 2 hours (7200 seconds). https://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime – Mark Jan 28 '21 at 12:44
  • also this could help: [How do I expire a PHP session after 30 minutes?](https://stackoverflow.com/q/520237/2932052) – Wolf Jan 28 '21 at 20:50

0 Answers0