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

mtseo opened this issue Apr 26, 2019 · 1 comment


None yet
2 participants
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);

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

function proxy_parser ($url){

    $curl = new Curl();


    $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 = '';

    foreach($proxy_result as $key => $val)

        $multi_curl->beforeSend(function ($instance) use ($proxy_result) {
            foreach ($proxy_result as $key => $val) {
        $instance->setOpt(CURLOPT_FOLLOWLOCATION, true);
        $instance->setOpt(CURLOPT_SSL_VERIFYHOST, false);
        $instance->setOpt(CURLOPT_SSL_VERIFYPEER, false);}});




    $multi_curl->success(function($instance) {
        $ip = ($instance->response->origin);
        echo $ip;
    //$ip = ($proxy_result->response->origin);
    //echo $ip;



$url = '';

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

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


This comment has been minimized.

Copy link

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();
    $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->success(function($instance) {
            $ip = $instance->response->origin;
            echo 'ip: ' . $ip . "\n";
        $multi_curls[] = $multi_curl;

    foreach ($multi_curls as $mc) {

$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.