[*] исправлен метод мемкэша и добавлена крайняя ошибка
This commit is contained in:
1 parent
a0ce19a311
commit
a849a80f61
2 files changed
+27
-5
No files matched your search
+3
-1
@@ -33,7 +33,9 @@ $DB->query('SET sql_mode = \'\''); // сбрасы
|
||||
CIoT::init($DB); // инициализация класса работы с контроллером
|
||||
CCache::init(CACHEDIR, CACHE_TTL, USE_CACHE); // инициализация модуля кэширования
|
||||
if(CACHE_TYPE == 'MEMCACHE') {
|
||||
CCache::useMemcache();
|
||||
if(!CCache::useMemcache()) {
|
||||
CEvents::add('Ошибка при включении memcache! Используется файловое хранилище. <code>'.CCache::getLastError().'</code>', 'warning', 'cache');
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['clear_cache']) and $_REQUEST['clear_cache'] =='Y') { // сброс кэша по запросу
|
||||
|
||||
@@ -61,6 +61,7 @@ class CCache
|
||||
*/
|
||||
private static $cache_enabled = true;
|
||||
|
||||
private static $lastError = '';
|
||||
/**
|
||||
* Инициализация кэша
|
||||
*
|
||||
@@ -250,14 +251,24 @@ class CCache
|
||||
|
||||
/**
|
||||
* Включение использования memcache вместо файлов
|
||||
*
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @return bool
|
||||
*/
|
||||
public static function useMemcache(string $host = 'localhost', int $port = 11211):void {
|
||||
self::$useMemcache = true;
|
||||
public static function useMemcache(string $host = 'localhost', int $port = 11211):bool {
|
||||
self::$memcacheHost = $host;
|
||||
self::$memcachePort = $port;
|
||||
self::$memcacheObject = new Memcache;
|
||||
self::$memcacheObject->connect( self::$memcacheHost, self::$memcachePort);
|
||||
return;
|
||||
$status = @self::$memcacheObject->connect( self::$memcacheHost, self::$memcachePort);
|
||||
if($status) {
|
||||
self::$useMemcache = true;
|
||||
return true;
|
||||
} else {
|
||||
self::$useMemcache = false;
|
||||
self::$lastError = 'Fail connect to Memcache! Host: '.self::$memcacheHost.', port: '.self::$memcachePort;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,5 +293,14 @@ class CCache
|
||||
self::$memcacheObject->flush();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение последней ошибки
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLastError():string {
|
||||
return self::$lastError;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user