Mausglov

Untitled

Oct 9th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. function clean_expire_cache($path = "") {
  2.     if (!class_exists("CFileCacheCleaner")) {
  3.         require_once ($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/cache_files_cleaner.php");
  4.     }
  5.     $curentTime = mktime();
  6.     if (defined("BX_CRONTAB") && BX_CRONTAB === true) $endTime = time() + 5; //Если на кроне, то работаем 5 секунд
  7.     else $endTime = time() + 1; //Если на хитах, то не более секунды
  8.     //Работаем со всем кешем
  9.     $obCacheCleaner = new CFileCacheCleaner("all");
  10.     if (!$obCacheCleaner->InitPath($path)) {
  11.         //Произошла ошибка
  12.         return "clean_expire_cache();";
  13.     }
  14.     $obCacheCleaner->Start();
  15.     while ($file = $obCacheCleaner->GetNextFile()) {
  16.         if (is_string($file)) {
  17.             $date_expire = $obCacheCleaner->GetFileExpiration($file);
  18.             if ($date_expire) {
  19.                 if ($date_expire < $curentTime) {
  20.                     unlink($file);
  21.                 }
  22.             }
  23.             if (time() >= $endTime) break;
  24.         }
  25.     }
  26.     if (is_string($file)) {
  27.         return "clean_expire_cache(\"" . $file . "\");";
  28.     }
  29.     else {
  30.         return "clean_expire_cache();";
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment