CodeIgniter Forums
Session Garbage collection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Session Garbage collection (/showthread.php?tid=86995)



Session Garbage collection - RichardKeasley - 03-03-2023

On some shared hosting, PHP's automatic Garbage collection is effectively disabled, and replaced with a CRON job (session.gc_probability and session.gc_divisor are set so garbage collection never happens)

Because CodeIgniter stores session files in the "writeable" folder, the CRON job does not clear the files and the disk fills up.

https://forum.codeigniter.com/showthread.php?tid=86930&highlight=garbage

\App\Config\Session::sessionExpiration sets the ini value for session.gc_maxlifetime

Can we add \App\Config\Session::sessionProbability


sessionProbability will ini_set session.gc_probability and session.gc_divisor


RE: Session Garbage collection - InsiteFX - 03-04-2023

session.gc_maxlifetime=[choose smallest possible]
Code:
session.gc_maxlifetime
 is a setting for deleting obsolete session ID. Reliance on this setting is [i]not[/i] recommended.
Developers should manage the lifetime of sessions with a timestamp by themselves.


Session GC (garbage collection) is best performed by using session_gc(). The session_gc() 

function should be executed by a task managers. E.g. cron on UNIX like systems.