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.

  • Basically SOCKS or can HTTP proxy? - ArcherGodson
  • HTTP proxy and so work. The problem is that I get a proxy from the list, where a substantial part uses SOCKS technology. So at least 70% of all working proxies are lost. - Elstein
  • The thing is that SOCKS can be cut by hosting, since it is not a native HTTP protocol. - ArcherGodson
  • Thanks, I will look at this direction. Is this some kind of ban or just the absence of the necessary library? - Elstein
  • I won’t say about the php library, because I don’t know him so well, but you can run your script directly on the hosting to see if there are any php /твой/скрипт.php errors / 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

1 answer 1

Hoster helped deal with the problem. According to him, by a similar method, I sent DNS requests through a proxy, which is why an error occurred. The right decision was to replace CURLPROXY_SOCKS5 with CURLPROXY_SOCKS5_HOSTNAME, and CURLPROXY_SOCKS4 with CURLPROXY_SOCKS4A, which helped.