ProxyUtils.php 1008 Bytes
<?php

class ProxyUtils {
	static function addProxyForCurl(&$ch) {
		if ( defined(PROXY_HOST) ) {
			$proxy_host = PROXY_HOST;
			if (!empty($proxy_host)) {
				curl_setopt($ch, CURLOPT_PROXY, "http://".$proxy_host);
				$proxy_userpwd = PROXY_USERPWD;
				if (!empty($proxy_userpwd)) {
						curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpwd);
				}
			}
		}
	}

	static function getStreamContextWithProxy() {
		if (!defined(PROXY_HOST))
					return;
		$proxy_host = PROXY_HOST;
		if (empty($proxy_host))
					return;
		$options = array(
			'http' => array(
					'method' => 'GET',
					'timeout' => '5',
					'user_agent' => 'PHP libxml agent',
					'ignore_errors' => true,
				)
			);
			
		$options['http']['proxy'] = 'tcp://'.$proxy_host;
		$options['http']['request_fulluri'] = TRUE;
		$proxy_userpwd = PROXY_USERPWD;
		if (!empty($proxy_userpwd)) {
			$options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode($proxy_userpwd);
		}
		return stream_context_create($options);
	}
}
?>