php-如何发送多个xml请求(Web服务)

时间:2019-01-29 09:58:29

标签: php web-services

我没有找到有关如何同时(同时)发出多个Web服务请求的任何示例。

这是我发送的请求,以获取酒店详细信息:

$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);

(XML“ HotelInfo”是请求)

我想同时向多个系统(网址)发送相同的请求。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

php本质上不会这样做,但是您可以使用另一个库,例如 GuzzleHttp

示例

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');

}

您还可以使用以下解决方案:https://github.com/amphp/amp

另一种使用python的解决方案:ThreadPoolExecutor

请参阅python文档中的内容:Concurrent Execution

相关问题