U
U
Us592019-05-23 22:04:19
PHP
Us59, 2019-05-23 22:04:19

Why is Multi-curl not returning a Timeout error?

Multi Curl does not give a Time out error, I tried to check what it would return curl_getinfo($handle["url"], CURLINFO_HTTP_CODE);and I see int(0), and as I understand it, the connection was not established and the server did NOT return a normal response (200).
I check for errors

curl_error, curl_errno и пробовал также curl_multi_errno

they don't return anything...
I decided to check through the usual curl to make a request from the same proxy IP address and with a normal CURL request they get Time out (which is what is needed).
Here is the multi curl code itself:
spoiler
public function MultiRequest ($data)
    {
        $multi = curl_multi_init();
        $handles = [];
        $array = [];

        foreach ($data as $key)
        {
            $ch = curl_init();
            $url = "https://httpbin.org/ip";
            curl_setopt_array($ch, array(
                CURLOPT_URL            => $url,
                CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
                CURLOPT_PROXY          => $key["Ip"] . ':' . $key["Port"],
                CURLOPT_PROXYTYPE      => CURLPROXY_HTTP,
                CURLOPT_TIMEOUT        => 50,
                CURLOPT_CONNECTTIMEOUT => 50,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_CUSTOMREQUEST  => 'GET',
                CURLOPT_ENCODING       => 'gzip, deflate'
            ));

            curl_multi_add_handle($multi, $ch);

            $handles[] = array(
                'url'           => $ch,
                'Ip'            => $key["Ip"],
                'QtyVerifyTime' => $key["QtyVerifyTime"]
            );
        }

        $active = null;
        do {
            $mrc = curl_multi_exec($multi, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);


        while ($active && $mrc == CURLM_OK) {
            if (curl_multi_select($multi) == -1) {
                usleep(10000);
                // continue; 
            }

            do {
                $mrc = curl_multi_exec($multi, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);

        }

        foreach ($handles as $handle)
        {
            $result = curl_multi_getcontent($handle["url"]);
            $statusCode = curl_getinfo($handle["url"], CURLINFO_HTTP_CODE);
            var_dump($statusCode); // выдает  int(0)

            if (curl_error($handle["url"])) {
                echo curl_error($handle["url"]); // ошибок нет!
            }

            if (curl_errno($handle["url"])) {
                echo curl_errno($handle["url"]); // ошибок нет!
            }

            curl_multi_remove_handle($multi, $handle["url"]);
        }

        curl_multi_close($multi);

        return $array;
    }

This is how I tested with the usual function:
spoiler
public function TestProxy ()
    {
        $array = [];    
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, 'https://httpbin.org/ip');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

        curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
        curl_setopt($ch, CURLOPT_PROXY, '11.22.33.44:80');
        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

        $result = curl_exec($ch);
        var_dump($result);

        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        return $array;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question