Пример #1
0
 /**
  * clear expired cached files
  * >> >php index.php "/cron/deleteExpiredCacheData"
  * @param \Base $f3
  */
 function deleteExpiredData(\Base $f3)
 {
     $time_start = microtime(true);
     // cache dir (dir is recursively searched...)
     $cacheDir = $f3->get('TEMP');
     $filterTime = (int) strtotime('-' . $f3->get('PATHFINDER.CACHE.EXPIRE_MAX') . ' seconds');
     $expiredFiles = Search::getFilesByMTime($cacheDir, $filterTime);
     $deletedFiles = 0;
     $deletedSize = 0;
     $notWritableFiles = 0;
     $deleteErrors = 0;
     foreach ($expiredFiles as $filename => $file) {
         /**
          * @var $file \SplFileInfo
          */
         if ($file->isWritable()) {
             $tmpSize = $file->getSize();
             if (unlink($file->getRealPath())) {
                 $deletedSize += $tmpSize;
                 $deletedFiles++;
             } else {
                 $deleteErrors++;
             }
         } else {
             $notWritableFiles++;
         }
     }
     $execTime = microtime(true) - $time_start;
     // Log ------------------------
     $log = new \Log('cron_' . __FUNCTION__ . '.log');
     $log->write(sprintf(self::LOG_TEXT, __FUNCTION__, $deletedFiles, $deletedSize, $notWritableFiles, $deleteErrors, $execTime));
 }
Пример #2
0
 /**
  * get cache folder size as string
  * @param \Base $f3
  * @return array
  */
 protected function getCacheData(\Base $f3)
 {
     // get all cache -----------------------------------------------------------------------------------------
     $cacheFilesAll = Search::getFilesByMTime($f3->get('TEMP'));
     $bytesAll = 0;
     foreach ($cacheFilesAll as $filename => $file) {
         $bytesAll += $file->getSize();
     }
     // get data cache -----------------------------------------------------------------------------------------
     $cacheFilesData = Search::getFilesByMTime($f3->get('TEMP') . 'cache/');
     $bytesData = 0;
     foreach ($cacheFilesData as $filename => $file) {
         $bytesData += $file->getSize();
     }
     return ['all' => $this->convertBytes($bytesAll), 'data' => $this->convertBytes($bytesData), 'template' => $this->convertBytes($bytesAll - $bytesData)];
 }