使用代理,使用curl,在localhost上工作但不在服务器上工作

时间:2011-08-12 20:21:39

标签: php curl proxy vps

我使用squid在我的一个vps上设置代理,然后我制作了这个代理脚本,它在wamp上工作正常,在localhost上,但是当我将它上传到我的服务器时它无法工作,我似乎无法找出原因。

$proxy = "xx.xx.xxx.xx:3128";
$proxy = explode(':', $proxy);
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/1.0 (googlebot@googlebot.com http://googlebot.com/)');
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8" ); 
curl_setopt($ch, CURLOPT_REFERER, "http://tamilwin.com/"); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec ($ch);

提前感谢。

更新

我在服务器上遇到的错误是cURL error number:7cURL error:couldn't connect to host

2 个答案:

答案 0 :(得分:0)

代理主机可能无效。 尝试telnet xx.xx.xxx.xx 3128(从您的本地PC) 你能成功连接吗?

答案 1 :(得分:0)

我遇到类似的问题,在localhost上工作得很好但在我的服务器上却没有。我写了一个检测脚本,让你知道它是否有效。

 state = {
        Case: this.props.Case,
        notesToShow: this.props.Case.slice(0, parseInt(this.props.AmountToShow, 10)).reverse(),
        isOpen: false,
        note: '',
    }