// Проверяем работоспособность прокси на PHP через CURL function proveryaem_rabotosposobnost_proxy_cherez_curl ($host_and_port, $prxy_auth = '', $url = "https://www.google.com.ua/", $timeout = 5){ $proxy = $host_and_port; $ch = curl_init(); // Initialise a cURL handle // Setting proxy option for cURL if (isset($proxy)) { // If the $proxy variable is set, then curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable } // Set any other cURL options that are required // curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxy_auth); // Если понадобится авторизация на прокси. $prxy_auth = 'login:pass' curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // Определяет кол-во времени на попытку соединения https://toster.ru/q/418924 curl_setopt($ch, CURLOPT_URL, $url); $results = curl_exec($ch); // Execute a cURL request //curl_close($ch); // Closing the cURL handle if ($results === false) { echo "Proxy is not working: ", curl_error($ch); } else { //print the output echo "OK"; } } // Пример вызова proveryaem_rabotosposobnost_proxy_cherez_curl ('35.246.154.253:3128'); // Процедурно $host = '118.179.206.162'; $port = 9999; $host = '35.246.154.253'; $port = 3128; $host_port = '118.179.206.162:9999'; $host_port = '35.246.154.253:3128'; // $proxy = 'login:pass@xx.xxx.18.25:8080'; $url = "https://www.google.com.ua/"; $proxy = '35.246.154.251:3128'; $ch = curl_init(); // Initialise a cURL handle // Setting proxy option for cURL if (isset($proxy)) { // If the $proxy variable is set, then curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable } // Set any other cURL options that are required // curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxy_auth); // Если понадобится авторизация на прокси. $prxy_auth = 'login:pass' curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, 5); // Определяет кол-во времени на попытку соединения https://toster.ru/q/418924 curl_setopt($ch, CURLOPT_URL, $url); $results = curl_exec($ch); // Execute a cURL request //curl_close($ch); // Closing the cURL handle if ($results === false) { echo "Proxy is not working: ", curl_error($ch); } else { //print the output echo "OK"; }
Комментарии
Если у вас есть вопрос, критика или другое мнение - напишите в комментариях.