Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicurl Individual proxy for each instance #582

Closed
mtseo opened this issue Apr 26, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@mtseo
Copy link

commented Apr 26, 2019

I'm having trouble with starting each instance with individual proxy. Trying to set MultiCurl, but I'm getting my IP as origin. Could you please help me?


require __DIR__ . '/vendor/autoload.php';


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);


    /* 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);


 




    }

    $multi_curl->success(function($instance) {
        $ip = ($instance->response->origin);
        echo $ip;
    });
    $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';




do {
    proxy_parser ($url);
    $file = file('proxies.txt');
    $number_proxies = sizeof($file);
    str_pad('', 4096, "\n");
    sleep(2);
} while ($number_proxies < 50);

echo "Прокси успешно спаршены";

@zachborboa

This comment has been minimized.

Copy link
Collaborator

commented Apr 29, 2019

Hi, It looks like explode should be on \r\n and there is an extra foreach loop that should be removed. Here's a simplified version that works:

use \Curl\Curl;
use \Curl\MultiCurl;

function proxy_parser($url){
    $curl = new Curl();
    $curl->get($url);
    $proxy_list = explode("\r\n", trim($curl->response));
    $proxy_list = array_slice($proxy_list, 0, 5); // testing

    $multi_curls = array();
    foreach ($proxy_list as $proxy) {
        $multi_curl = new MultiCurl();
        $multi_curl->setProxy($proxy);
        $multi_curl->setProxyType(CURLPROXY_SOCKS5);
        $multi_curl->setProxyTunnel();
        $multi_curl->addGet('http://httpbin.org/get');
        $multi_curl->success(function($instance) {
            $ip = $instance->response->origin;
            echo 'ip: ' . $ip . "\n";
        });
        $multi_curls[] = $multi_curl;
    }

    foreach ($multi_curls as $mc) {
        $mc->start();
    }
}

$url = 'https://api.proxyscrape.com/?request=displayproxies&proxytype=socks5&timeout=1000&anonymity=elite&ssl=yes&limit=200';
proxy_parser($url);

@zachborboa zachborboa closed this Apr 29, 2019

zachborboa added a commit to zachborboa/php-curl-class that referenced this issue May 12, 2019

Fix php-curl-class#572,php-curl-class#582: Add MultiCurl::setProxies(…
…) to make multicurl requests with multiple proxies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.