From a849a80f6128f4de7865ee23c7cd47cccededb61 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Tue, 21 Dec 2021 23:07:43 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=BC=D0=BA=D1=8D=D1=88=D0=B0=20=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D0=B9=D0=BD=D1=8F=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/bootstrap.php | 4 +++- inc/lib/CCache.class.php | 28 ++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/inc/bootstrap.php b/inc/bootstrap.php index 92c0082..2f91b81 100644 --- a/inc/bootstrap.php +++ b/inc/bootstrap.php @@ -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! Используется файловое хранилище. '.CCache::getLastError().'', 'warning', 'cache'); + } } if(isset($_REQUEST['clear_cache']) and $_REQUEST['clear_cache'] =='Y') { // сброс кэша по запросу diff --git a/inc/lib/CCache.class.php b/inc/lib/CCache.class.php index 442e85c..46b2891 100644 --- a/inc/lib/CCache.class.php +++ b/inc/lib/CCache.class.php @@ -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; + } } ?> \ No newline at end of file