• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/data/configurator/memcachedconnectionconfigurator.php
  • Класс: BitrixMainDataConfiguratorMemcachedConnectionConfigurator
  • Вызов: MemcachedConnectionConfigurator::createConnection
public function createConnection(): ?Memcached
{
	if (!$this->servers)
	{
		throw new NotSupportedException('Empty server list to memcache connection.');
	}

	$connectionTimeout = $this->getConfig()['connectionTimeout'] ?? 1;
	$serializer = $this->getConfig()['serializer'] ?? Memcached::SERIALIZER_PHP;

	$connection = new Memcached();
	$connection->setOption(Memcached::OPT_CONNECT_TIMEOUT, $connectionTimeout);
	$connection->setOption(Memcached::OPT_SERIALIZER, $serializer);

	$result = false;
	if (!empty($this->servers))
	{
		foreach ($this->servers as $server)
		{
			$success = $connection->addServer(
				$server['host'],
				$server['port'],
				$server['weight']
			);

			if ($success)
			{
				$result = $success;
			}
		}

		$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;
}