在新浪云PHP运行环境设置代理

新浪云PHP7的运行环境支持设置http代理,PHP5.3和PHP5.6的环境不支持。

如何使用

<?php  
function curl_string ($url, $user_agent, $proxy)  
{

       $ch = curl_init();
       curl_setopt ($ch, CURLOPT_PROXY, $proxy);
       curl_setopt ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 1);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $result = curl_exec ($ch);
       curl_close($ch);
       return $result;
}

$url_page = "http://ip.cn";
$user_agent = "Mozilla/4.0";
// 以下换成你自己的代理即可。
$proxy = "http://178.62.96.126:8118";
$string = curl_string($url_page,$user_agent,$proxy);
var_dump($string);