Good evening. Faced with such a problem, SOCKS proxies do not work on hosting through CURL. On the home server, everything is fine, but on the hosting there is an error "Failed to resolve" site "for SOCKS4 connect. Actually, the code itself:
<? $start = microtime(true); $file = 'proxyList.txt'; $proxyList = []; $fp = fopen ($file, "r+"); $proxy=fread($fp,filesize($file)); $proxys=explode(PHP_EOL,$proxy); $mh = curl_multi_init(); print_r($proxys); foreach($proxys as $proxy){ $proxy=explode(":",$proxy); echo $ip=$proxy[0]; echo $port=$proxy[1]; if(isset($proxy[2])){ $type=$proxy[2]; } if ( !$ip || !$port ) continue; if(isset($proxy[2])){ $proxy = $ip . ':' . $port. ':' . $type; }else{ $proxy = $ip . ':' . $port; } $curlh[$proxy]= curl_init(); curl_setopt($curlh[$proxy],CURLOPT_TIMEOUT, 10); curl_setopt($curlh[$proxy], CURLOPT_URL, 'https://www.google.com'); curl_setopt($curlh[$proxy], CURLOPT_FOLLOWLOCATION, true); curl_setopt($curlh[$proxy], CURLOPT_RETURNTRANSFER, true); curl_setopt($curlh[$proxy], CURLOPT_NOBODY, true); curl_setopt($curlh[$proxy], CURLOPT_HEADER, true); curl_setopt($curlh[$proxy], CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36'); curl_setopt($curlh[$proxy], CURLOPT_PROXY, $ip . ":" . $port ); if(isset($type)) { if(stripos($type,"SOCKS5")!==false){ curl_setopt ($curlh[$proxy], CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } if (stripos($type, "SOCKS4") !== false) { curl_setopt($curlh[$proxy], CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); } if (stripos($type, "HTTP") !== false) { curl_setopt($curlh[$proxy], CURLOPT_PROXYTYPE, CURLPROXY_HTTP); } } curl_setopt($curlh[$proxy], CURLOPT_HTTPPROXYTUNNEL, true); curl_multi_add_handle($mh, $curlh[$proxy]); } $running = null; do { curl_multi_exec($mh, $running); } while ($running); foreach ($curlh as $key => $value) { curl_multi_remove_handle($mh, $curlh[$key]); echo curl_error ($curlh[$key]) . "<br>"; } foreach ($curlh as $key => $value) { $response[$key] = curl_multi_getcontent($curlh[$key]); } foreach($response as $key=> $out){ if ( strpos($out, 'Forbidden') == true ){ continue;} if ( strpos($out, '200 OK') == true ){ array_push($proxyList,$key);} } if ( count($proxyList) ) { unlink($file); if ($fp = fopen ($file, "w")) { for ($i=0;$i<count($proxyList);$i++) fwrite ($fp, $proxyList[$i] . PHP_EOL); fclose ($fp); } } echo '<pre>'; print_r($proxyList); echo '</pre>'; $time = microtime(true) - $start; printf('Скрипт выполнялся %.4F сек.', $time); Actually, the problem is hosting. What exactly is needed to use SOCKS proxy? What technology library? Thank you for attention.
PS I use a proxy exclusively for collecting and analyzing information, no DDOS, data theft and other things.
php /твой/скрипт.phperrors / your /php /твой/скрипт.php, you may have to change it a bit so that it runs from shell But I would put on the limitations of the host. This is just a hunch. - ArcherGodson