public function collectGarbage()
{
// counter to store the number of removed sessions
$sessionRemovalCount = 0;
// we want to know what inactivity timeout we've to check the sessions for
$inactivityTimeout = $this->getSessionSettings()->getInactivityTimeout();
// iterate over the found session items
foreach (new \ApcIterator(ApcSessionHandler::APCU_CACHE_TYPE_USER) as $item) {
// explode the APC item
extract($item);
// unpersist the session
$session = $this->unpersist($key);
// load the sessions last activity timestamp
$lastActivitySecondsAgo = time() - $session->getLastActivityTimestamp();
// query whether or not the session has been expired
if ($lastActivitySecondsAgo > $inactivityTimeout) {
// if yes, delete the file + raise the session removal count
$this->delete($key);
$sessionRemovalCount++;
}
}
// return the number of removed sessions
return $sessionRemovalCount;
}