Add servers to the server pool of the cache specified
Used for memcache PECL extension.

@param \Memcache $cache
@param MemCacheServer[] $servers
186329
protected function addMemcacheServers($cache, $servers)
    {
        $class = new \ReflectionClass($cache);
        $paramCount = $class->getMethod('addServer')->getNumberOfParameters();
        foreach ($servers as $server) {
            // $timeout is used for memcache versions that do not have $timeoutms parameter
            $timeout = (int) ($server->timeout / 1000) + (($server->timeout % 1000 > 0) ? 1 : 0);
            if ($paramCount === 9) {
                $cache->addServer(
                    $server->host,
                    $server->port,
                    $server->persistent,
                    $server->weight,
                    $timeout,
                    $server->retryInterval,
                    $server->status,
                    $server->failureCallback,
                    $server->timeout
                );
            } else {
                $cache->addServer(
                    $server->host,
                    $server->port,
                    $server->persistent,
                    $server->weight,
                    $timeout,
                    $server->retryInterval,
                    $server->status,
                    $server->failureCallback
                );
            }
        }
    }
922121
protected function registerMemcachedBucketCacheDriver(): void
    {
        $this->app['cache']->extend('couchbase-memcached', function ($app, $config) {
            $prefix = $app['config']['cache.prefix'];
            $credential = $config['sasl'] ?? [];
            $memcachedBucket = $this->app['couchbase.memcached.connector']
                ->connect($config['servers']);

            return new Repository(
                new MemcachedBucketStore(
                    $memcachedBucket,
                    strval($prefix),
                    $config['servers'],
                    $credential
                )
            );
        });
    }
402890
public function connect(array $servers, $connectionId = null, array $options = [], array $credentials = [])
    {
        $memcached = $this->getMemcached(
            $connectionId, $credentials, $options
        );

        if (! $memcached->getServerList()) {
            // For each server in the array, we'll just extract the configuration and add
            // the server to the Memcached connection. Once we have added all of these
            // servers we'll verify the connection is successful and return it back.
            foreach ($servers as $server) {
                $memcached->addServer(
                    $server['host'], $server['port'], $server['weight']
                );
            }
        }

        return $this->validateConnection($memcached);
    }
1174825
public function addServers(array $servers)
    {
        foreach ($servers as $server) {
            $this->addServer(
                $server[0],
                $server[1],
                isset($server[2]) ? $server[2] : null
            );
        }
    }
778782
protected function configureProcessors(array $processors)
    {
        foreach ($processors as $processorName => $processorOptions) {
            $processorLoader = new ProcessorLoader($processorOptions, $this->processors);
            $this->processors[$processorName] = $processorLoader->load();
        }
    }
943156
private function parseConfiguredServers(array $servers): Collection
    {
        $result = new Collection();

        foreach ($servers as $server) {
            if (is_array($server)) {
                if (!empty(array_except($server, ['host', 'port', 'timeout']))) {
                    throw new InvalidConfigurationException('Servers in array notation may only contain a host, port and timeout parameter.');
                }
                if (!array_has($server, 'host')) {
                    throw new InvalidConfigurationException('For servers in array notation, the host parameter is required.');
                }

                $host = Arr::get($server, 'host');
                $port = Arr::get($server, 'port');
                $timeout = Arr::get($server, 'timeout', self::DEFAULT_TIMEOUT);

                $result->push(new Server($host, $port, $timeout));
            } else if (is_string($server)) {
                $result->push(new Server($server, null, self::DEFAULT_TIMEOUT));
            } else {
                throw new InvalidConfigurationException('The server configuration may only contain arrays or strings.');
            }
        }

        return $result;
    }
1305893
protected function validateConnection($memcached)
    {
        $status = $memcached->getVersion();

        if (! is_array($status)) {
            throw new RuntimeException('No Memcached servers added.');
        }

        if (in_array('255.255.255', $status) && count(array_unique($status)) === 1) {
            throw new RuntimeException('Could not establish Memcached connection.');
        }

        return $memcached;
    }
548862
private function connect()
	{
		// We want to only create the driver once.
		if ($this->driver)
		{
			return;
		}

		$pool = $this->options['memcache.pool'];

		if ($pool)
		{
			$this->driver = new \Memcached($pool);
		}
		else
		{
			$this->driver = new \Memcached;
		}

		$this->driver->setOption(\Memcached::OPT_COMPRESSION, $this->options['memcache.compress'] ?: false);
		$this->driver->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
		$serverList = $this->driver->getServerList();

		// If we are using a persistent pool we don't want to add the servers again.
		if (empty($serverList))
		{
			$servers = $this->options['memcache.servers'] ?: array();

			foreach ($servers as $server)
			{
				$this->driver->addServer($server->host, $server->port);
			}
		}
	}
141582
public function addServers(array $servers): self
    {
        foreach ($servers as $hostname => $server) {
            if (!$server instanceof Server && is_array($server)) {
                $host = $server['host'];
                $port = $server['port'] ?? null;
                $database = $server['database'] ?? null;
                $username = $server['username'] ?? null;
                $password = $server['password'] ?? null;
                $options = $server['options'] ?? null;

                $server = new Server($host, $port, $database, $username, $password, $options);
            }

            /* @var Server $server */
            if (!is_string($hostname)) {
                $hostname = $server->getHost();
            }

            $this->addServer($hostname, $server);
        }

        return $this;
    }
1070361
private function addProcessors(array $processors)
    {
        // We need to reverse the array because Monolog "pushes" processors to top of the stack
        foreach (array_reverse($processors) as $processor) {
            $this->logger->pushProcessor($processor);
        }
    }
123020
public function create(array $servers)
    {
        if (empty($servers)) {
            throw new \RuntimeException(sprintf('Empty configuration passed to %s::create() method.', __CLASS__));
        }

        foreach ($servers as $server) {
            $this->memcached->addServer(
                $server['host'], $server['port'], $server['weight']
            );
        }

        $status = $this->memcached->getVersion();

        if (in_array('255.255.255', $status) && count(array_unique($status)) === 1) {
            throw new \RuntimeException('Could not establish Memcached connection.');
        }

        return $this->memcached;
    }
516066
public void addServerSocket(
      InternalInstrumented<ServerStats> server, InternalInstrumented<SocketStats> socket) {
    ServerSocketMap serverSockets = perServerSockets.get(id(server));
    assert serverSockets != null;
    add(serverSockets, socket);
  }
1069758
protected function memcache_init()
    {
        $this->mc_available = 0;

        // add all configured hosts to pool
        $pconnect       = $this->config->get('memcache_pconnect', true);
        $timeout        = $this->config->get('memcache_timeout', 1);
        $retry_interval = $this->config->get('memcache_retry_interval', 15);

        foreach ($this->config->get('memcache_hosts', array()) as $host) {
            if (substr($host, 0, 7) != 'unix://') {
                list($host, $port) = explode(':', $host);
                if (!$port) $port = 11211;
            }
            else {
                $port = 0;
            }

            $this->mc_available += intval($this->memcache->addServer(
                $host, $port, $pconnect, 1, $timeout, $retry_interval, false, array($this, 'memcache_failure')));
        }
    }
82439
public List<MemcachedServer> activeServers() {
        ArrayList<MemcachedServer> active = new ArrayList<MemcachedServer>(servers.length);
        for (MemcachedServer server : servers) {
            if (server.isActive()) {
                active.add(server);
            }
        }
        return active;
    }
517527
public function addCache(CacheInterface $cache)
    {
        $this->cacheMap[$cache->getName()] = $cache;
        $this->cacheNames[]                = $cache->getName();
    }
94386
public function connectToServers()
    {
        //Array for the list of server(s) to connect
        $addServers  = [];
        
        //Get all server already connected (persistent)
        $serversList = $this->obtainConnectedServerList();
        
        //Loop on server declared into config
        foreach ($this->config['servers'] as $server) {
            $this->completeServerInfos($server);
            
            $host   = $server['host'];
            $port   = $server['port'];
            $weight = $server['weight'];
            
            //not check if port = (int) 0; Doc said to define to 0 for socket.
            if (empty($host) || $port === null) {
                continue;
            }
            
            //search if the reading server is not already connected
            if (in_array($host.':'.$port, $serversList)) {
                continue;
            }
            
            \BFW\Application::getInstance()
                ->getMonolog()
                ->getLogger()
                ->debug(
                    'Try to connect to memcached server.',
                    [
                        'host' => $host,
                        'port' => $port
                    ]
                );
            
            //If not, add the server at the list to connect
            $addServers[] = [$host, $port, $weight];
        }

        //Connect to server(s)
        $this->addServers($addServers);
        
        //Check if connect is successfull
        $this->testConnect();
    }
1024316
public static function setArrayAccessCache(\ArrayAccess $cache)
    {
        self::$cacheImplementation = new ArrayAccessCacheAdapter($cache);
        self::$hasBeenCleared      = false;
    }