/** * Connect to the remote server * * Will try to connect to the proxy server. If no proxy was set, will * fall back to the target server (behave like regular Socket adapter) * * @param string $host * @param int $port * @param boolean $secure * @param int $timeout */ public function connect($host, $port = 80, $secure = false) { // If no proxy is set, fall back to Socket adapter if (!$this->config['proxy_host']) { return parent::connect($host, $port, $secure); } // Go through a proxy - the connection is actually to the proxy server $host = $this->config['proxy_host']; $port = $this->config['proxy_port']; // If we are connected to the wrong proxy, disconnect first if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) { if (is_resource($this->socket)) { $this->close(); } } // Now, if we are not connected, connect if (!is_resource($this->socket) || !$this->config['keepalive']) { $this->socket = @fsockopen($host, $port, $errno, $errstr, (int) $this->config['timeout']); if (!$this->socket) { $this->close(); require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Unable to Connect to proxy server ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr); } // Set the stream timeout if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) { require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout'); } // Update connected_to $this->connected_to = array($host, $port); } }
public function connect($host, $port = 80, $secure = false) { if (!isset($this->_ips[$host])) { $this->_ips[$host] = gethostbyname($host); } $this->_ip = $this->_ips[$host]; return parent::connect($this->_ip, $port, $secure); }
/** * Connect to the remote server * * Will try to connect to the proxy server. If no proxy was set, will * fall back to the target server (behave like regular Socket adapter) * * @param string $host * @param int $port * @param boolean $secure */ public function connect($host, $port = 80, $secure = false) { // If no proxy is set, fall back to Socket adapter if (!$this->config['proxy_host']) { return parent::connect($host, $port, $secure); } // Connect (a non-secure connection) to the proxy server return parent::connect($this->config['proxy_host'], $this->config['proxy_port'], false); }
/** * Connect to the remote server * * Will try to connect to the proxy server. If no proxy was set, will * fall back to the target server (behave like regular Socket adapter) * * @param string $host * @param int $port * @param boolean $secure */ public function connect($host, $port = 80, $secure = false) { // If no proxy is set, fall back to Socket adapter if (!$this->config['proxy_host']) { return parent::connect($host, $port, $secure); } /* Url might require stream context even if proxy connection doesn't */ if ($secure) { $this->config['sslusecontext'] = true; } // Connect (a non-secure connection) to the proxy server return parent::connect($this->config['proxy_host'], $this->config['proxy_port'], false); }
/** * Connect to the remote server * * @param string $host Host name * @param int $port Port number * @param bool $secure Secure flag * * @return void */ public function connect($host, $port = 80, $secure = false) { if (Mage::app()->useCache(self::CACHE_TYPE)) { $mode = $this->getConfigData('cache_mode'); if (!($mode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_ONLY)) { try { parent::connect($host, $port, $secure); } catch (Zend_Http_Client_Adapter_Exception $e) { Mage::log("{$this->_code} [socket]: {$e->getMessage()}"); } } } else { parent::connect($host, $port, $secure); } }
/** * Connect to the remote server * * @param string $host * @param int $port * @param boolean $secure * @param int $timeout */ public function connect($host, $port = 80, $secure = false) { $this->log("Connecting to: {$host}:{$port}"); return parent::connect($host, $port, $secure); }