ProxyUtils.php
1003 Bytes
<?php
class ProxyUtils {
static function addProxyForCurl(&$ch) {
if (defined('PROXY_HOST')) {
curl_setopt($ch, CURLOPT_PROXY, "http://".PROXY_HOST);
if (defined('PROXY_USERPWD')) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, PROXY_USERPWD);
}
}
}
static function getStreamContextWithProxy() {
if (!defined('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;
if (defined('PROXY_USERPWD')) {
$options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(PROXY_USERPWD);
}
return stream_context_create($options);
}
}
?>