Answer the question
In order to leave comments, you need to log in
Checking Socks5 proxy through multi curl does not work well. And HTTP proxies are perfect. Why is this happening?
Hello everyone.
I have a virtual VPS server.
nginx + php fpm
100Mbps
_
I need to always have fresh proxies.
Since I take public proxies, I need to check them often. For these purposes, Multi curl was chosen.
I wrote a class in PHP and check the proxy like this:
$cmh = curl_multi_init();
foreach($proxies as $k=>$v){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://'.$domain."/?".mt_rand(0,999));
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36");
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_PROXY, $v);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_multi_add_handle($cmh, $ch);
$tasks[$v] = $ch;
}
do {
$mrc = curl_multi_exec($cmh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($cmh) != -1) {
do {
$mrc = curl_multi_exec($cmh, $active);
$info = curl_multi_info_read($cmh);
if ($info['msg'] == CURLMSG_DONE) {
$ch = $info['handle'];
$getinfo = curl_getinfo($ch);
$retcode = $getinfo['http_code'];
$proxy = array_search($ch, $tasks);
$phptime = microtime(1)-$startphptime;
$totaltime = $getinfo['total_time'];
// пока проверяю только код ответа, потом буду проверять сам ответ
if($retcode==200){
$this->good[] = array($proxy,$retcode,$phptime,$totaltime);
}else{
$this->bad[] = array($proxy,$retcode,$phptime,$totaltime);
}
}
usleep(100);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
usleep(100);
}
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question