本文整理汇总了PHP中Zend_Http_Client_Adapter_Socket::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Http_Client_Adapter_Socket::connect方法的具体用法?PHP Zend_Http_Client_Adapter_Socket::connect怎么用?PHP Zend_Http_Client_Adapter_Socket::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Http_Client_Adapter_Socket
的用法示例。
在下文中一共展示了Zend_Http_Client_Adapter_Socket::connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* 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);
}
}
示例2: connect
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);
}
示例3: connect
/**
* 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);
}
示例4: connect
/**
* 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);
}
示例5: connect
/**
* 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);
}
}
示例6: connect
/**
* 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);
}