Triggering garbage collection for sessions

Hi,

there is a garbage collection function in SessionManager.inc.php. When/where is this function triggered?

best,
Carola

function gc($maxlifetime) {

 return $this->sessionDao->deleteByLastUsed(time() - 86400, Config::getVar('general', 'session_lifetime') <= 0 ? 0 : time() - Config::getVar('general', 'session_lifetime') * 86400);

}

Hi @carola,

This is a feature supported by PHP’s internal session management interface. When session_set_save_handler is called in lib/pkp/classes/session/SessionManager.inc.php, OJS specifies gc as the garbage collection function. See the PHP documentation for session_set_save_handler for details – particularly the gc parameter there.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks a lot, Alec.

For others who might be interested:

The garbage collector callback is invoked internally by PHP periodically in order to purge old session data. The frequency is controlled by session.gc_probability and session.gc_divisor.

best,
Carola