I have a code using curl_multi_excec function, But it is returning http code 200 and 0 that means alternately. This is my code snippet:
try{
        $allproducts = json_decode(self::getProductbyEan());
        //An array that will contain all of the information
        //relating to each request.
        $requests = array();
        //Initiate a multiple cURL handle
        $mh = curl_multi_init();
        //Loop through each URL.
        foreach($allproducts as $k => $url){
            $url = 'https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/'.$url->id.'.json';
            $requests[$k] = array();
            $requests[$k]['url'] = $url;
            //Create a normal cURL handle for this particular request.
            $requests[$k]['curl_handle'] = curl_init($url);
            //Configure the options for this request.
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_RETURNTRANSFER, true);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_TIMEOUT, 10);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($requests[$k]['curl_handle'], CURLOPT_USERPWD, "$login:$password");
            //Add our normal / single cURL handle to the cURL multi handle.
            curl_multi_add_handle($mh, $requests[$k]['curl_handle']);
        }
        //Execute our requests using curl_multi_exec.
        $stillRunning = false;
        curl_multi_setopt ( $mh , CURLMOPT_MAXCONNECTS, 5);
        do {
            curl_multi_exec($mh, $stillRunning);
        } while ($stillRunning);
        //Loop through the requests that we executed.
        foreach($requests as $k => $request){
            //Remove the handle from the multi handle.
            curl_multi_remove_handle($mh, $request['curl_handle']);
            //Get the response content and the HTTP status code.
            $requests[$k]['http_code'] = curl_getinfo($request['curl_handle'], CURLINFO_HTTP_CODE);
            //Close the handle.
            curl_close($requests[$k]['curl_handle']);
        }
        //Close the multi handle.
        curl_multi_close($mh);
        //var_dump the $requests array for example purposes.
        print_r($requests);
    }catch(Exception $e){
        wp_die($e->getMessage());
    }
and this is the output of the result:
[0] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/1155551.json
        [curl_handle] => Resource id #75
        [http_code] => 200
    )
[1] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/6345345334.json
        [curl_handle] => Resource id #76
        [http_code] => 0
    )
[2] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/45456456.json
        [curl_handle] => Resource id #77
        [http_code] => 200
    )
[3] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/145555.json
        [curl_handle] => Resource id #78
        [http_code] => 0
    )
[4] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/2qw22w.json
        [curl_handle] => Resource id #79
        [http_code] => 200
    )
[5] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/5025155024034.json
        [curl_handle] => Resource id #80
        [http_code] => 0
    )
[6] => Array
    (
        [url] => https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/5025155023983.json
        [curl_handle] => Resource id #81
        [http_code] => 200
    )
As you can see that the http_code result shows that there were some instances that it returns 200 and 0. Any help would be appreciated. Thanks in advance
 
    