0
最近写了一个简单的卷曲程序来测试代理。如果我得到curl的输出,我使用的代理是好的,我保存它,并可以使用它,否则它是下降,忙碌等...卷曲和代理
问题是,当我测试我得到输出的代理列表,但是当我只想从OK列表中选择一个输出时,我什么也得不到,尽管我实际上使用了几乎相同的代码。那就是:测试
代码(我测试完全相同的代理人):
$url='http://google.com';
$curl_imelimit=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($proxies as $pr)
foreach($pr as $proxy){
$ch=curl_init();
curl_setopt_array($ch, $options);
$output=curl_exec($ch);
$info=curl_getinfo($ch);
echo $output.'</br>';
if ($info['total_time']>0 && $info['total_time']<$allowed_time){
echo '<p style="color:green;">'.$proxy.' OK</p>';
}
if ($info['total_time']==0 || $info['total_time']>$allowed_time)
echo '<p style="color:red;">'.$proxy.' NOT GOOD</p>';
set_time_limit(30);
curl_close($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>';