2012-02-18 32 views
0

任何想法,我的代码是怎么了......我想通过代理在PHP卷曲功能连接...我假设代理工作BC我试图从这个几个代理使用curl名单http://hidemyass.com/proxy-list/search-234921但似乎无法得到任何正常运行...通过与PHP

的思考?

function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') 
{ 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); 
curl_setopt ($ch, CURLOPT_HEADER, 0); 
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_PROXY, '75.74.244.122:1523'); 
$data = curl_exec(); 
curl_close($ch); 
return $result; 
} 
+0

我建议首先尝试用自己的代理。通过这种方式,您可以查看代理日志以获取有关实际发生情况的更多信息。 – jap1968 2012-02-18 23:49:46

+0

如何设置我自己的代理? – user1179295 2012-02-19 00:00:22

+0

看看鱿鱼[http://www.squid-cache.org]。它是一个免费的开源代理。在那里您可以找到有关安装和管理的文档。 – jap1968 2012-02-19 10:26:28

回答

0

它看起来并不像你所使用的代理工作:

[email protected]:$ telnet 75.74.244.122 1523 
Trying 75.74.244.122... 
telnet: Unable to connect to remote host: Connection refused 
0

您可以通过使用随机逐一使用该脚本

尝试多个代理获取随机代理

function get_random_proxy(){ 
    srand ((double)microtime()*1000000); 
    $f_contents = file ("proxy.txt"); 
    $line = $f_contents[array_rand ($f_contents)]; 
    return $line; 
    } 

使用一个代理随机调用卷曲函数

function get_curl_proxy($url){ 

$proxy_ip = get_random_proxy(); 
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/532.4 (KHTML, like Gecko) Chrome/4.0.233.0 Safari/532.4"; 
$referer = "http://www.google.com/"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip); 
curl_setopt($ch, CURLOPT_REFERER, $referer); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 

$data = curl_exec($ch); 
curl_close($ch); 

return $data; 
} 

有关进一步的参考看到这个 http://altafphp.blogspot.in/2012/06/using-proxies-with-curl-in-php.html