Answer the question
In order to leave comments, you need to log in
How to check proxy with multiCurl and Php Curl Class?
Trying to check through multiCurl and PHP Curl Class ( https://github.com/php-curl-class/php-curl-class) proxy.
The problem is that I cannot set an individual proxy for each multiCurl process.
If you use sequentially run cycles for checking, then everything works fine.
Tell me where I went wrong, please:
<?php
require __DIR__ . '/vendor/autoload.php';
/**
* @param $url
*/
ini_set('max_execution_time', 600);
ini_set("display_errors",1);
error_reporting(E_ALL);
use \Curl\Curl;
use \Curl\MultiCurl;
function proxy_parser ($url){
$curl = new Curl();
$curl->get($url);
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->setOpt(CURLOPT_CONNECTTIMEOUT, 10);
$curl->setOpt(CURLINFO_HEADER_OUT, true);
$proxy_result = explode("\n", $curl->response);
// echo 'Response:' . "\n";
// var_dump($proxy_result);
/* Multicurl */
$multi_curl = new MultiCurl();
/* Проверка прокси */
$check_url = 'http://httpbin.org/get';
foreach($proxy_result as $key => $val)
{
$multi_curl->beforeSend(function ($instance) use ($proxy_result) {
foreach ($proxy_result as $key => $val) {
$instance->setProxy($val);
$instance->setProxyType(CURLPROXY_SOCKS5);
$instance->setProxyTunnel();
$instance->setConnectTimeout(5);
$instance->setTimeout(10);
$instance->setOpt(CURLOPT_FOLLOWLOCATION, true);
$instance->setOpt(CURLOPT_SSL_VERIFYHOST, false);
$instance->setOpt(CURLOPT_SSL_VERIFYPEER, false);}});
$multi_curl->addGet($check_url);
/*$curl = new Curl();
$curl->setProxy($val);
$curl->setProxyType(CURLPROXY_SOCKS5);
$curl->setProxyTunnel();
$curl->setConnectTimeout(5);
$curl->setTimeout(10);
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->get($check_url);*/
//$ip = ($curl->response->origin);
//echo $ip;
// if (strpos($proxyResponse, 'ХХХ') !== false)
// {
// $url_str = $val;
// $fd = fopen("proxies.txt", 'a') or die("не удалось создать файл");
// fwrite($fd, $url_str .PHP_EOL);
// fclose($fd);
// }
// else
// {
// continue;
//
// }// end if
}
$multi_curl->success(function($instance) {
$ip = ($instance->response->origin);
echo $ip;
// echo 'call to "' . $proxy_result->url . '" was successful.' . "\n";
// echo '<pre>' . var_dump($proxy_result->getRequestHeaders) . '</pre>';
});
$multi_curl->start();
//$ip = ($proxy_result->response->origin);
//echo $ip;
//var_dump($multi_curl);
die();
}
$url = 'https://api.proxyscrape.com/?request=displayproxies&proxytype=socks5&timeout=1000&anonymity=elite&ssl=yes&limit=200';
//$url = 'http://pubproxy.com/api/proxy?last_check=1&format=txt&level=anonymous&speed=10&limit=5&https=true&user_agent=true&cookies=true&referer=true';
do {
proxy_parser ($url);
$file = file('proxies.txt');
$number_proxies = sizeof($file);
str_pad('', 4096, "\n");
sleep(2);
} while ($number_proxies < 50);
echo "Прокси успешно спаршены";
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