Пример #1
0
 /**
  * Iterates over all existing sessions and removes their data if the inactivity
  * timeout was reached.
  *
  * @return integer The number of outdated entries removed
  * @api
  */
 public function collectGarbage()
 {
     if ($this->inactivityTimeout === 0) {
         return 0;
     }
     if ($this->metaDataCache->has('_garbage-collection-running')) {
         return false;
     }
     $sessionRemovalCount = 0;
     $this->metaDataCache->set('_garbage-collection-running', true, [], 120);
     foreach ($this->metaDataCache->getIterator() as $sessionIdentifier => $sessionInfo) {
         if ($sessionIdentifier === '_garbage-collection-running') {
             continue;
         }
         $lastActivitySecondsAgo = $this->now - $sessionInfo['lastActivityTimestamp'];
         if ($lastActivitySecondsAgo > $this->inactivityTimeout) {
             if ($sessionInfo['storageIdentifier'] === null) {
                 $this->systemLogger->log('SESSION INFO INVALID: ' . $sessionIdentifier, LOG_WARNING, $sessionInfo);
             } else {
                 $this->storageCache->flushByTag($sessionInfo['storageIdentifier']);
                 $sessionRemovalCount++;
             }
             $this->metaDataCache->remove($sessionIdentifier);
         }
         if ($sessionRemovalCount >= $this->garbageCollectionMaximumPerRun) {
             break;
         }
     }
     $this->metaDataCache->remove('_garbage-collection-running');
     return $sessionRemovalCount;
 }