No autoremove of session files ? (in app/tmp/sessions , Cakephp2)


I wonder if there’s a ready-way to auto remove expired session files?

timeout won’t delete the session file and will just make it expired, and the file won’t be deleted from app/tmp/sessions. In a long term it can take a lot of space in the server if you have traffic.

Configure::write('Session', array(
		'defaults' => 'cake',
		'timeout' => 1, //36000

Otherwise I’ll probably do a script or a php function that checks regularly the session files to remove old ones based on their modification date.


Session timeout and session garbage collection are two different operations, and the latter doesn’t happen immediately, but with a certain probability on session startup.

You have to configure the relevant PHP INI settings accordingly, check session.gc_probability, session.gc_divisor, and session.gc_maxlifetime (this one is being set automatically by CakePHP, derived from the timeout option).