【发布时间】:2012-10-12 04:44:25
【问题描述】:
我的这段代码在我的本地服务器上运行良好,但在实时服务器上无法运行。
我正在尝试在不被阻止的情况下进行报废。
如果代理被远程服务器阻止,那么它为什么在我的本地服务器上工作?
function curl_se($set_url,$proxy){
$ch = curl_init($set_url);
//set options
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; //browsers keep this blank.
//set options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
echo "<pre>";
print_r(curl_getinfo($ch));
echo "</pre>";
if(curl_errno($ch))
return false;
else
return $result;
}
在每个 curl 请求上循环一个代理。
$proxy = array(
"91.83.216.186:8081",
"190.116.88.11:8080",
"117.102.9.116:8080",
"188.165.4.38:3128",
"187.120.209.10:8080",
"190.186.50.32:3128",
"190.108.83.30:8080",
"190.130.230.149:8080",
"130.180.18.24:8275",
"178.33.181.120:8080"
);
在实时服务器上,我收到 curl 错误 7 (CURLE_COULDNT_CONNECT)
我卡住了,相同的代码相同的 URL 在本地工作正常。
更新:我发现这与代理有关。我尝试了数百个,但没有一个在实时服务器上运行,出现 curl 错误 7;也尝试了不同的网站 URL。 虽然相同的代理和 URL 在我的本地服务器上工作。
【问题讨论】:
-
您确定您的
$set_url没有指向您本地主机上的某个位置吗??? -
是的,实际上过去 2 天它在实时服务器上也运行良好。今天早上它停止工作了。我在 2 个不同的实时服务器上对其进行了测试。同样的错误!
-
var_dump(file_get_contents($set_url))??你得到了什么 -
警告:file_get_contents(azlyrics.com/z/zaz.html) [function.file-get-contents]:打开流失败:HTTP 请求失败!在 /srv/disk1/1025371/www/farzoaq.com/output/clone_azlyrics/test_url.php 第 2 行 bool(false)
-
可能是我的实时服务器 ip 被远程服务器阻止了这就是我使用代理的原因