public function connect($host, $port, $timeout = null)
    {
        $uuid = $this->uuid($host, $port);

        if ($timeout === null) {
            $timeout = $this->getTimeout();
        }

        // The error variables
        $errorNumber = null;
        $errorString = 'n.a.';

        if (isset(self::$connections[$this->getPersistentId()][$uuid]) === false) {
            if ($timeout !== null) {
                $connection = @fsockopen(
                    $host,
                    $port,
                    $errorNumber,
                    $errorString,
                    $timeout
                );
            } else {
                $connection = @fsockopen(
                    $host,
                    $port,
                    $errorNumber,
                    $errorString
                );
            }

            // Check for failed connection
            if (is_resource($connection) === false || $errorNumber !== 0) {
                throw new Exception(
                    sprintf(
                        'Error "%s: %s" while connecting to Memcached on host: %s:%s (UUID: %s)',
                        $errorNumber,
                        $errorString,
                        $host,
                        $port,
                        $uuid
                    )
                );
            }

            // Store for further access/use ...
            self::$connections[$this->getPersistentId()][$uuid] = $connection;

        } else {
            $connection = self::$connections[$this->getPersistentId()][$uuid];
        }

        return $connection;
    }
public function connect($host, $port, $timeout = null)
    {
        $uuid = $this->uuid($host, $port);

        if ($timeout === null) {
            $timeout = $this->getTimeout();
        }

        // The error variables
        $errorNumber = null;
        $errorString = 'n.a.';

        if (isset(self::$connections[$this->getPersistentId()][$uuid]) === false) {
            if ($timeout !== null) {
                $connection = @fsockopen(
                    $host,
                    $port,
                    $errorNumber,
                    $errorString,
                    $timeout
                );
            } else {
                $connection = @fsockopen(
                    $host,
                    $port,
                    $errorNumber,
                    $errorString
                );
            }

            // Check for failed connection
            if (is_resource($connection) === false || $errorNumber !== 0) {
                throw new Exception(
                    sprintf(
                        'Error "%s: %s" while connecting to Memcached on host: %s:%s (UUID: %s)',
                        $errorNumber,
                        $errorString,
                        $host,
                        $port,
                        $uuid
                    )
                );
            }

            // Store for further access/use ...
            self::$connections[$this->getPersistentId()][$uuid] = $connection;

        } else {
            $connection = self::$connections[$this->getPersistentId()][$uuid];
        }

        return $connection;
    }
public function connect ( $ host , $ port , $ timeout = null ) { $ uuid = $ this -> uuid ( $ host , $ port ) ; if ( $ timeout === null ) { $ timeout = $ this -> getTimeout ( ) ; } // The error variables $ errorNumber = null ; $ errorString = 'n.a.' ; if ( isset ( self :: $ connections [ $ this -> getPersistentId ( ) ] [ $ uuid ] ) === false ) { if ( $ timeout !== null ) { $ connection = @ fsockopen ( $ host , $ port , $ errorNumber , $ errorString , $ timeout ) ; } else { $ connection = @ fsockopen ( $ host , $ port , $ errorNumber , $ errorString ) ; } // Check for failed connection if ( is_resource ( $ connection ) === false || $ errorNumber !== 0 ) { throw new Exception ( sprintf ( 'Error "%s: %s" while connecting to Memcached on host: %s:%s (UUID: %s)' , $ errorNumber , $ errorString , $ host , $ port , $ uuid ) ) ; } // Store for further access/use ... self :: $ connections [ $ this -> getPersistentId ( ) ] [ $ uuid ] = $ connection ; } else { $ connection = self :: $ connections [ $ this -> getPersistentId ( ) ] [ $ uuid ] ; } return $ connection ; }
Connects to a Memcached host.

@param string   $host    The host to connect to
@param int      $port    The port the Memcached daemon is listening on
@param int|null $timeout Timeout in seconds

@author Benjamin Carl <opensource@clickalicious.de>
@return resource|null The resource (socket) on success, otherwise NULL
@access public
@throws \Clickalicious\Memcached\Exception
Connects to a Memcached host .