title: How do I send multiple SOAP Requests in a loop: PHP?
body: <p>Am using PHP curl to do SOAP requests to a webservice, I have an array of IDs of over 500 items, for each ID, I send a SOAP request and get a XML response for which I test some parameters and generate/store in a variable. Unfortunately, I can only loop through 9 IDs of the array, over which I get a "500 Server error" in firebug on a jquery post.
  How do I loop through ALL these 500 items? Could it be done with parallel connections OR multi-threading? If so how do you it in PHP curl?</p>
  
  <p>Here is my sample code.</p>
  
  <pre><code>&lt;?php 
  $VehicleIDs = "153,106,128,149,121,123,125,133,130,115,124,116,102,100,101,103,144,113,...........";//over 500 items
  $VehicleIDsArray = explode(",", $VehicleIDs);
  
  for($i=0; $i &lt;= count($massVehicleIDsArray); $i++){
              $soapUrl = "http://xxx.asmx";
              $xml_post_string = '&lt;?xml version="1.0" encoding="utf-8"?&gt;
                              &lt;soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
                                &lt;soap:Body&gt;
                                  &lt;GetInUseEventsForVehicleID&gt;
                                    &lt;VehicleID&gt;'.$massVehicleIDsArray[$i].'&lt;/VehicleID&gt;
                                  &lt;/GetInUseEventsForVehicleID&gt;
                                &lt;/soap:Body&gt;
                              &lt;/soap:Envelope&gt;';
  
          $headers = array(
                      "Content-type: text/xml;charset=\"utf-8\"",
                      "Accept: text/xml",
                      "Cache-Control: no-cache",
                      "Pragma: no-cache",
                      "SOAPAction: xxx", // your op URL
                      "Content-length: ".strlen($xml_post_string),
                  );
          // PHP cURL  for https connection with auth
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($ch, CURLOPT_URL, $soapUrl);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
          curl_setopt($ch, CURLOPT_TIMEOUT, 10);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // xml request
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  
          // converting
          $response = curl_exec($ch); 
          curl_close($ch);
  
          // converting
          $response1 = str_replace("&lt;soap:Body&gt;","",$response);
          $response2 = str_replace("&lt;/soap:Body&gt;","",$response1);
  
          // convertingc to XML
          $parser = simplexml_load_string($response2);   
  
          /*....................
  
          MORE CODE TO COMPARE EACH SOAP RESPONSE
  
          ...................*/
  }
  ?&gt;
  </code></pre>
  
  <p>Thank you</p>