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

	$connectionTimeout = $this->getConfig()['connectionTimeout'] ?? 1;
	$connection = new Memcache();

	$result = false;
	if (count($this->servers) === 1)
	{
		['host' => $host, 'port' => $port] = $this->servers[0];
		$result = $connection->pconnect($host, $port, $connectionTimeout);
	}
	else
	{
		foreach ($this->servers as $server)
		{
			$success = $connection->addServer(
				$server['host'],
				$server['port'],
				true,
				$server['weight'],
				$connectionTimeout
			);

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

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