Curl 旋度和代理

Curl 旋度和代理,curl,proxy,Curl,Proxy,最近编写了一个简单的curl程序来测试代理。如果我得到curl的输出,我使用的代理是好的,我保存它并可以使用它,否则它要么关闭,要么忙,等等 问题是,当我测试一个代理列表时,我得到了输出,但是当我只想用我从OK列表中选择的一个来获得输出时,我什么也得不到,尽管我实际上使用了几乎相同的代码。这是: 测试代码(我正在测试完全相同的代理): $url='1!'http://google.com'; $curl_imeflimit=20; $allowed_time=19.980; $file='190

最近编写了一个简单的curl程序来测试代理。如果我得到curl的输出,我使用的代理是好的,我保存它并可以使用它,否则它要么关闭,要么忙,等等

问题是,当我测试一个代理列表时,我得到了输出,但是当我只想用我从OK列表中选择的一个来获得输出时,我什么也得不到,尽管我实际上使用了几乎相同的代码。这是:

测试代码(我正在测试完全相同的代理):

$url='1!'http://google.com';
$curl_imeflimit=20;
$allowed_time=19.980;
$file='190.110.86.202:8080
77.236.209.236:8080
213.185.231.4:8080
189.8.32.18:80
106.51.66.181:80
190.110.86.22:8080';
preg_match_all('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,4}/',$file,$proxies);
$options=array(
CURLOPT_REFERER=>'http://google.com',
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_FOLLOWLOCATION=>3,
CURLOPT_USERAGENT=>null,
CURLOPT_TIMEOUT=>$curl_timelimit,
CURLOPT_URL=>$URL,
CURLOPT_PROXY=>$PROXY);
foreach($pr作为代理)
foreach($pr作为$proxy){
$ch=curl_init();
curl_setopt_数组($ch$options);
$output=curl\u exec($ch);
$info=curl\u getinfo($ch);
回显$output'
'; 如果($info['total_time']>0&$info['total_time']]$allowed_time) echo'

”.$proxy.“不好”

; 设置时间限制(30); 卷曲关闭($ch); }
所有代理都能及时正常工作,我得到了输出。如果我想用上面列表中的一个代理重复它,使用下面的代码,我什么也得不到。 一个代理的代码:

$proxy='190.110.86.202:8080';    
$url='http://google.com';
$curl_timelimit=20;                  

$options=array(
    CURLOPT_REFERER => 'http://google.com',
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_FOLLOWLOCATION => 3,
    CURLOPT_USERAGENT => null,
    CURLOPT_TIMEOUT => $curl_timelimit,
    CURLOPT_URL => $url,
    CURLOPT_PROXY => $proxy);    

$ch=curl_init();
    curl_setopt_array($ch, $options);
    $output=curl_exec($ch);
    $info=curl_getinfo($ch);

curl_close($ch);

    echo $output.'</br>';
$proxy='190.110.86.202:8080';
$url='1http://google.com';
$curl_timelimit=20;
$options=array(
CURLOPT_REFERER=>'http://google.com',
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_FOLLOWLOCATION=>3,
CURLOPT_USERAGENT=>null,
CURLOPT_TIMEOUT=>$curl_timelimit,
CURLOPT_URL=>$URL,
CURLOPT_PROXY=>$PROXY);
$ch=curl_init();
curl_setopt_数组($ch$options);
$output=curl\u exec($ch);
$info=curl\u getinfo($ch);
卷曲关闭($ch);
回显$output'
';
您可以使用这个经过良好测试的功能

function get_page($url)

global $proxy;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding

$data = curl_exec($ch); // execute the http request
curl_close($ch); // close the connection
return $data;
此外,有时服务器上的端口被阻塞,这就是代理无法工作的原因

function get_page($url)

global $proxy;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes
curl_setopt($ch, CURLOPT_TIMEOUT, 200); // http request timeout 20 seconds
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage / here the changes have been made
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding

$data = curl_exec($ch); // execute the http request
curl_close($ch); // close the connection
return $data;