如何为每个具有不同发布数据的多个 URI 创建异步请求?
我能够获取每个 URI 的数据,但我想让它异步。
另外,如果请求时间过长,我该如何超时?
我的代码:
//url
$ur1 = 'www.exaample1.com';
$ur2 = 'www.Test.com';
//xml
$ur1_xml = ''; // xml code
$ur2_xml = ''; // xml code
//headers
$ur1_header = array("POST HTTP/1.1",
"Content-type: application/xml; charset=\"utf-8\"",
"Content-length: " . strlen($ur1_xml));
$ur2_header = array("POST HTTP/1.1",
"Content-type: application/xml; charset=\"utf-8\"",
"Content-length: " . strlen($ur2_xml));
$client = new Client();
// make request
$request = new Request('POST', $ur1_url, $ur1_headers,$ur1_xml);
$promise = $client->sendAsync($request)->then(function ($response) {
echo '<pre>';
print_r(simplexml_load_string($response->getBody()));
echo '</pre>';
});
die();