function getHttpRetriever($path) { //Including depends if (!class_exists("http")) { if (defined('LIB_HTTP_PATH')) { require_once LIB_HTTP_PATH . "/http.php"; } } $httpClient = new http(HTTP_V11, false); $parsedUrl = parse_url($path); $httpClient->host = isset($parsedUrl['host']) ? $parsedUrl['host'] : $this->host; $httpClient->port = isset($parsedUrl['port']) ? $parsedUrl['port'] : 80; $path = $parsedUrl['path'] . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : ''); $proxySettings = isset($this->_websites_config[$this->host]['proxy']) ? $this->_websites_config[$this->host]['proxy'] : $this->_websites_config['default']['proxy']; if ($proxySettings) { $parsedUrl = parse_url($proxySettings); $httpClient->use_proxy($parsedUrl['host'], $parsedUrl['port'], $parsedUrl['user'], $parsedUrl['pass']); } if (isset($this->_websites_config['default']['user_agent'])) { $httpClient->user_agent = $this->_websites_config['default']['user_agent']; } if (isset($this->_websites_config[$this->host]['user_agent'])) { $httpClient->user_agent = $this->_websites_config[$this->host]['user_agent']; } $connectionTimeout = isset($this->_websites_config[$this->host]['connection_timeout']) ? $this->_websites_config[$this->host]['connection_timeout'] : (isset($this->_websites_config['default']['connection_timeout']) ? $this->_websites_config['default']['connection_timeout'] : 30); $httpClient->connection_timeout = $connectionTimeout; return $httpClient; }
<?php /********************************************************************* * Demonstrates the use of requests via proxy *********************************************************************/ header('Content-Type: text/plain'); require_once 'http.inc'; $http_client = new http(HTTP_V11, false); $http_client->host = 'www.yahoo.com'; $http_client->use_proxy('ns.crs.org.ni', 3128); if ($http_client->get('/') == HTTP_STATUS_OK) { print_r($http_client); } else { print 'Server returned ' . $http_client->status; } unset($http_client); ?>