title: doing cURL request on a foreach loop returning http code 200 and 0 alternately
body: <p>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:</p>
  
  <pre><code>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 =&gt; $url){
  
              $url = 'https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/'.$url-&gt;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 =&gt; $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-&gt;getMessage());
      }
  </code></pre>
  
  <p>and this is the output of the result:</p>
  
  <pre><code>[0] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/1155551.json
          [curl_handle] =&gt; Resource id #75
          [http_code] =&gt; 200
      )
  
  [1] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/6345345334.json
          [curl_handle] =&gt; Resource id #76
          [http_code] =&gt; 0
      )
  
  [2] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/45456456.json
          [curl_handle] =&gt; Resource id #77
          [http_code] =&gt; 200
      )
  
  [3] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/145555.json
          [curl_handle] =&gt; Resource id #78
          [http_code] =&gt; 0
      )
  
  [4] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/2qw22w.json
          [curl_handle] =&gt; Resource id #79
          [http_code] =&gt; 200
      )
  
  [5] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/5025155024034.json
          [curl_handle] =&gt; Resource id #80
          [http_code] =&gt; 0
      )
  
  [6] =&gt; Array
      (
          [url] =&gt; https://nartastaging.retailpath.com.au/cgi-bin/WebObjects/NARTAStaging.woa/ra/Product/5025155023983.json
          [curl_handle] =&gt; Resource id #81
          [http_code] =&gt; 200
      )
  </code></pre>
  
  <p>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</p>