0

I didn't find any example of how to make several web-service request at the same time (simultaneous).

For instant, this is request I send in order to get hotel details:

$s = new soapclient("http://www.wb-service-address.com",array('wsdl'));
$HotelInfo = new stdClass;

<HotelInfo softwareID="123" SessionId="153" Lang="EN" InfoType="">
     <Hotel  ID="103" /> 
</HotelInfo>

$HotelInfo->xmlRequest = $paramsStr;
$result = $s->__call("SubmitXmlString",array($HotelInfo));
$obj_pros = get_object_vars($result);
$hotel_full_xml =  $obj_pros['SubmitXmlStringResult'];  
$hotel_full_xml = simplexml_load_string($hotel_full_xml);

(The XML "HotelInfo" is the request)

I would like to send the same request to number of systems (urls) at the same time.

I'll appreciate your help

Roi
  • 109
  • 3
  • 11
  • You can check out the answer to this post: https://stackoverflow.com/questions/29532168/multiple-api-calls-simultaneously-in-php. It might point you in the right direction. – M. Eriksson Jan 29 '19 at 10:08
  • you could use `curl_multi_*`. Allows the processing of multiple cURL handles asynchronously. – jibsteroos Jan 29 '19 at 10:12
  • @MagnusEriksson - Thanks! but i don't see any reference to request by XML... – Roi Jan 29 '19 at 10:24
  • @jibsteroos - thank you. i read about it but i didn't see any example of request with XML... – Roi Jan 29 '19 at 10:24
  • What you send is irrelevant. It's still just a HTTP-request. You can't do it with just `SoapClient`. – M. Eriksson Jan 29 '19 at 10:25
  • @MagnusEriksson - I understand, but I'm not sure how to write the part that send the RQ for hotelInfo. Can you help with that? – Roi Jan 29 '19 at 10:52
  • @MagnusEriksson - Can yo please help me with example? – Roi Jan 30 '19 at 06:33

1 Answers1

1

php by nature does not do that but you can using another library like GuzzleHttp

Exemple:

public function index()
{
 $promises = call_user_func(function () {
     foreach ($this->usernames as $username) {
         (yield $this->client->requestAsync('GET', 'https://api.github.com/users/' . $username));
     }
 });
 // Wait till all the requests are finished.
 \GuzzleHttp\Promise\all($promises)->then(function (array $responses) {
     $this->profiles = array_map(function ($response) {
         return json_decode($response->getBody(), true);
     }, $responses);
 })->wait();
 // Return JSON response
 $response = new Response();
 // StreamInterface objects are not immutable!
 $response->getBody()->write($this->html());
 return $response->withHeader('Content-type', 'text/html');

}

Also you can using this solution: https://github.com/amphp/amp

another solution with python: ThreadPoolExecutor

see that in python documentation: Concurrent Execution

Kurollo
  • 65
  • 6