/** * 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); } // If we are connected to a different server or port, disconnect first if ($this->curl && is_array($this->connected_to) && ($this->connected_to[0] != $host || $this->connected_to[1] != $port)) { $this->close(); } // Do the actual connection $this->curl = curl_init(); if ($port != 80) { curl_setopt($this->curl, CURLOPT_PORT, intval($port)); } // Go through a proxy - the connection is actually to the proxy server $host = $this->config['proxy_host']; $port = $this->config['proxy_port']; // curl_setopt ($this->curl, CURLOPT_HTTPPROXYTUNNEL, TRUE); // curl_setopt ($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt($this->curl, CURLOPT_PROXY, $host . ":" . $port); if (!$this->curl) { $this->close(); throw new Zend_Http_Client_Adapter_Exception('Unable to Connect to use proxy' . $host . ':' . $port); } // Update connected_to $this->connected_to = array($host, $port); }
/** * Delete content of media/js and media/css folders to refresh with updated compressed/minified js/css content * If disabled, the updates are done each time an original file is updated. Can be resource overload on live website. * * @param Mage_Core_Model_Observer $observer */ public function regenerateMediaFiles($observer) { if (Mage::getStoreConfigFlag('uioptimization/general/cronupdate') && (Mage::getStoreConfigFlag('uioptimization/csscompression/enabled') || Mage::getStoreConfigFlag('uioptimization/jscompression/enabled'))) { // Clean up media/css and media/js folders and recreate the folders if necessary try { Mage::getModel('core/design_package')->cleanMergedJsCss(); Mage::dispatchEvent('clean_media_cache_after'); } catch (Exception $e) { Mage::logException($e); return; } $stores = Mage::app()->getStores(); foreach ($stores as $id => $v) { $url = Zend_Uri_Http::fromString(Mage::app()->getStore($id)->getBaseUrl()); // Recreate the js and css compressed file by using the normal process try { $curl = new Zend_Http_Client_Adapter_Curl(); $curl->setCurlOption(CURLOPT_SSL_VERIFYPEER, false); $curl->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1); $curl->connect($url->getHost(), $url->getPort(), Mage_Core_Model_Store::isCurrentlySecure()); $curl->write(Zend_Http_Client::GET, $url); $curl->close(); Mage::log('[Diglin_UIOptimization_Model_Observer] Update media js/css content for the different stores', ZEND_LOG::DEBUG); } catch (Exception $e) { Mage::logException($e); return; } } } }
/** * Initialize curl * * @param string $host * @param int $port * @param boolean $secure * @return void * @throws Zend_Http_Client_Adapter_Exception if unable to connect */ public function connect($host, $port = 80, $secure = false) { parent::connect($host, $port, $secure); // for some reason the zend_http_client_adapter_curl only sets a timeout on // connecting, not on the reading. // So we override and set the same timeout being used for connecting as // the timeout for reading / writing. curl_setopt($this->_curl, CURLOPT_TIMEOUT, (int) $this->_config['timeout']); }
/** * @group ZF-7040 */ public function testGetCurlHandle() { $adapter = new Zend_Http_Client_Adapter_Curl(); $adapter->setConfig(array('timeout' => 2, 'maxredirects' => 1)); $adapter->connect("http://framework.zend.com"); $this->assertTrue(is_resource($adapter->getHandle())); }