我没有找到任何如何同时(同时)发出多个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"酒店信息"是请求)
我想同时向多个系统(url)发送相同的请求。
我会感谢您的帮助
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.
GuzzleHttpPromiseall($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文档:并发执行