app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php
protected function _connect() {
        $this->_varnishConn = fsockopen($this->_host, $this->_port, $errno,
            $errstr, $this->_timeout);
        if ( ! is_resource($this->_varnishConn)) {
            Mage::throwException(sprintf(
                'Failed to connect to Varnish on [%s:%d]: (%d) %s',
                $this->_host, $this->_port, $errno, $errstr ));
        }

        stream_set_blocking($this->_varnishConn, 1);
        stream_set_timeout($this->_varnishConn, $this->_timeout);

        //varnish 2.0 doesn't spit out a banner on connection, this will need
        //to be changed if 2.0 support is ever added
        $banner = $this->_read();
        if ($banner['code'] === self::CODE_AUTH) {
            $challenge = substr($banner['text'], 0, 32);
            $response = hash('sha256', sprintf("%s\n%s%s\n", $challenge,
                $this->_authSecret, $challenge));
            $banner = $this->_command('auth', self::CODE_OK, $response);
        }

        if ($banner['code'] !== self::CODE_OK) {
            Mage::throwException('Varnish admin authentication failed: '.
                $banner['text']);
        }

        if ($this->_version == null) { // If autodetecting
            $this->_version = $this->_determineVersion($banner['text']);
        }

        return $this->isConnected();
    }
protected function _connect() {
        $this->_varnishConn = fsockopen($this->_host, $this->_port, $errno,
            $errstr, $this->_timeout);
        if ( ! is_resource($this->_varnishConn)) {
            Mage::throwException(sprintf(
                'Failed to connect to Varnish on [%s:%d]: (%d) %s',
                $this->_host, $this->_port, $errno, $errstr ));
        }

        stream_set_blocking($this->_varnishConn, 1);
        stream_set_timeout($this->_varnishConn, $this->_timeout);

        //varnish 2.0 doesn't spit out a banner on connection, this will need
        //to be changed if 2.0 support is ever added
        $banner = $this->_read();
        if ($banner['code'] === self::CODE_AUTH) {
            $challenge = substr($banner['text'], 0, 32);
            $response = hash('sha256', sprintf("%s\n%s%s\n", $challenge,
                $this->_authSecret, $challenge));
            $banner = $this->_command('auth', self::CODE_OK, $response);
        }

        if ($banner['code'] !== self::CODE_OK) {
            Mage::throwException('Varnish admin authentication failed: '.
                $banner['text']);
        }

        if ($this->_version == null) { // If autodetecting
            $this->_version = $this->_determineVersion($banner['text']);
        }

        return $this->isConnected();
    }
protected function _connect ( ) { $ this -> _varnishConn = fsockopen ( $ this -> _host , $ this -> _port , $ errno , $ errstr , $ this -> _timeout ) ; if ( ! is_resource ( $ this -> _varnishConn ) ) { Mage :: throwException ( sprintf ( 'Failed to connect to Varnish on [%s:%d]: (%d) %s' , $ this -> _host , $ this -> _port , $ errno , $ errstr ) ) ; } stream_set_blocking ( $ this -> _varnishConn , 1 ) ; stream_set_timeout ( $ this -> _varnishConn , $ this -> _timeout ) ; //varnish 2.0 doesn't spit out a banner on connection, this will need //to be changed if 2.0 support is ever added $ banner = $ this -> _read ( ) ; if ( $ banner [ 'code' ] === self :: CODE_AUTH ) { $ challenge = substr ( $ banner [ 'text' ] , 0 , 32 ) ; $ response = hash ( 'sha256' , sprintf ( "%s\n%s%s\n" , $ challenge , $ this -> _authSecret , $ challenge ) ) ; $ banner = $ this -> _command ( 'auth' , self :: CODE_OK , $ response ) ; } if ( $ banner [ 'code' ] !== self :: CODE_OK ) { Mage :: throwException ( 'Varnish admin authentication failed: ' . $ banner [ 'text' ] ) ; } if ( $ this -> _version == null ) { // If autodetecting $ this -> _version = $ this -> _determineVersion ( $ banner [ 'text' ] ) ; } return $ this -> isConnected ( ) ; }
Establish a connection to the configured Varnish instance

@return boolean
Establish a connection to the configured Varnish instance