PHP - 如何确保curl_multi代理连接是否成功? [英] PHP - How to make sure if a curl_multi proxy connection was succesful?
本文介绍了PHP - 如何确保curl_multi代理连接是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用多cURL与代理,但我不知道如何检查每个代理连接是否成功。使用正常的单个cURL我做一个简单的循环,运行时,curl_errno不是0.
I want to use multi-cURL with proxies, but I can't figure out how to check if each proxy connection was succesful. With a the normal single cURL I make a simple loop which runs as long curl_errno isn't 0.
但是如何使用多cURL?
But how to make with multi-cURL?
感谢!
推荐答案
您可以有一个简单的代理检查程序,多卷曲
You can have a simple proxy checker before you run your query on multi-curl
简单代理检查程序
function __proxyChecker($proxy)
{
$ch = curl_init("http://google.com");
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_NOBODY, true);
$handle = curl_exec($ch);
curl_close($ch);
return $handle ;
}
使用
$proxies = "211.136.10.29:80
88.146.161.215:3128
211.136.10.29:80
61.35.0.39:6515
77.78.197.15:8080
211.161.152.106:80";
$proxies = explode("\n", $proxies);
//shuffle($proxies);
$url = "http://google.com";
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
echo "<pre>";
foreach ( $proxies as $proxy ) {
$proxy = trim($proxy);
if(empty($proxy))
continue ;
if(__proxyChecker($proxy))
echo $proxy , " - ok \n";
else
echo $proxy , " - bad \n";
}
输出
211.136.10.29:80 - ok
88.146.161.215:3128 - ok
211.136.10.29:80 - ok
61.35.0.39:6515 - bad
77.78.197.15:8080 - bad
211.161.152.106:80 - ok
这篇关于PHP - 如何确保curl_multi代理连接是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文