Example #1
0
 /**
  * Remove expired upload sessions
  */
 private function removeExpiredSessions($uploadCache)
 {
     $cacheRoot = $uploadCache->getCacheRoot();
     if (empty($cacheRoot) || !is_dir($cacheRoot)) {
         return;
     }
     $cacheRoot = rtrim($cacheRoot, '/\\');
     $lastFullScan = $uploadCache->getLastFullScanTimestamp();
     $currentTimestamp = time();
     // Do not scan all cache too often
     if ($lastFullScan + $this->_cacheAliveTimeout / 2 > $currentTimestamp) {
         return;
     }
     $dirs = scandir($cacheRoot);
     foreach ($dirs as $dir) {
         if ($dir != '.' && $dir != '..' && is_dir($cacheRoot . DIRECTORY_SEPARATOR . $dir)) {
             $uploadCache = new UploadCache($cacheRoot);
             $uploadSessionId = $dir;
             if ($uploadCache->getWriteTimestamp($uploadSessionId) + $this->_cacheAliveTimeout < $currentTimestamp) {
                 $uploadCache->cleanUploadSessionCache($uploadSessionId);
             }
         }
     }
     $uploadCache->setLastFullScanTimestamp($currentTimestamp);
 }