protected function configure(Memcached $memcached, array $connections, OptionsBag $options)
    {
        $binary = $options->getBoolean('binary_protocol');
        $needsAuth = $options->get('username') && $options->get('password');

        if ($needsAuth) {
            // SASL is only supported with binary protocol,
            // just enable it instead of throwing exception.
            $binary = true;

            if (!constant($this->class . '::HAVE_SASL')) {
                throw new RuntimeException('memcached extension needs to be built with SASL support to use username and password');
            }
        }

        $memcached->setOptions([
            Memcached::OPT_BINARY_PROTOCOL        => $binary,
            Memcached::OPT_LIBKETAMA_COMPATIBLE   => $options->getBoolean('consistent_hash'),
            Memcached::OPT_SERVER_FAILURE_LIMIT   => $options->getInt('server_failure_limit', 1), // See #3
            Memcached::OPT_NUMBER_OF_REPLICAS     => $options->getInt('number_of_replicas'),
            Memcached::OPT_RANDOMIZE_REPLICA_READ => $options->getBoolean('randomize_replica_read'),
            Memcached::OPT_REMOVE_FAILED_SERVERS  => $options->getBoolean('remove_failed_servers'),
            Memcached::OPT_CONNECT_TIMEOUT        => $options->getInt('connect_timeout'),
        ]);

        if ($needsAuth) {
            $memcached->setSaslAuthData($options->get('username'), $options->get('password'));
        }

        foreach ($connections as $conn) {
            $memcached->addServer($conn['host'], $conn['port'], $conn['weight']);
        }
    }
protected function configure(Memcached $memcached, array $connections, OptionsBag $options)
    {
        $binary = $options->getBoolean('binary_protocol');
        $needsAuth = $options->get('username') && $options->get('password');

        if ($needsAuth) {
            // SASL is only supported with binary protocol,
            // just enable it instead of throwing exception.
            $binary = true;

            if (!constant($this->class . '::HAVE_SASL')) {
                throw new RuntimeException('memcached extension needs to be built with SASL support to use username and password');
            }
        }

        $memcached->setOptions([
            Memcached::OPT_BINARY_PROTOCOL        => $binary,
            Memcached::OPT_LIBKETAMA_COMPATIBLE   => $options->getBoolean('consistent_hash'),
            Memcached::OPT_SERVER_FAILURE_LIMIT   => $options->getInt('server_failure_limit', 1), // See #3
            Memcached::OPT_NUMBER_OF_REPLICAS     => $options->getInt('number_of_replicas'),
            Memcached::OPT_RANDOMIZE_REPLICA_READ => $options->getBoolean('randomize_replica_read'),
            Memcached::OPT_REMOVE_FAILED_SERVERS  => $options->getBoolean('remove_failed_servers'),
            Memcached::OPT_CONNECT_TIMEOUT        => $options->getInt('connect_timeout'),
        ]);

        if ($needsAuth) {
            $memcached->setSaslAuthData($options->get('username'), $options->get('password'));
        }

        foreach ($connections as $conn) {
            $memcached->addServer($conn['host'], $conn['port'], $conn['weight']);
        }
    }
protected function configure ( Memcached $ memcached , array $ connections , OptionsBag $ options ) { $ binary = $ options -> getBoolean ( 'binary_protocol' ) ; $ needsAuth = $ options -> get ( 'username' ) && $ options -> get ( 'password' ) ; if ( $ needsAuth ) { // SASL is only supported with binary protocol, // just enable it instead of throwing exception. $ binary = true ; if ( ! constant ( $ this -> class . '::HAVE_SASL' ) ) { throw new RuntimeException ( 'memcached extension needs to be built with SASL support to use username and password' ) ; } } $ memcached -> setOptions ( [ Memcached :: OPT_BINARY_PROTOCOL => $ binary , Memcached :: OPT_LIBKETAMA_COMPATIBLE => $ options -> getBoolean ( 'consistent_hash' ) , Memcached :: OPT_SERVER_FAILURE_LIMIT => $ options -> getInt ( 'server_failure_limit' , 1 ) , // See #3 Memcached :: OPT_NUMBER_OF_REPLICAS => $ options -> getInt ( 'number_of_replicas' ) , Memcached :: OPT_RANDOMIZE_REPLICA_READ => $ options -> getBoolean ( 'randomize_replica_read' ) , Memcached :: OPT_REMOVE_FAILED_SERVERS => $ options -> getBoolean ( 'remove_failed_servers' ) , Memcached :: OPT_CONNECT_TIMEOUT => $ options -> getInt ( 'connect_timeout' ) , ] ) ; if ( $ needsAuth ) { $ memcached -> setSaslAuthData ( $ options -> get ( 'username' ) , $ options -> get ( 'password' ) ) ; } foreach ( $ connections as $ conn ) { $ memcached -> addServer ( $ conn [ 'host' ] , $ conn [ 'port' ] , $ conn [ 'weight' ] ) ; } }
Configure a new Memcached instance. This isn't needed for existing persisted connections.

@param Memcached  $memcached
@param array      $connections
@param OptionsBag $options
Configure a new Memcached instance . This isn t needed for existing persisted connections .