我的getAsync()
班上有这个HTTP
public static function getAsync($urls) {
try {
$client = new Client();
$options = [
'http_errors' => false,
'connect_timeout' => 3.14,
'read_timeout' => 3.14,
'timeout' => 3.14,
'verify' => false,
];
$headers = [
'headers' => [
'Keep-Alive' => 'timeout=300'
]
];
foreach ($urls as $name => $url) {
$promises[$name] = $client->requestAsync('GET', $url, $headers, $options);
}
$results = Promise\settle($promises)->wait();
$array = [];
foreach ($results as $name => $data) {
if ($data['state'] === 'fulfilled') {
$array[$name] = json_decode($data['value']->getBody()->getContents(),TRUE);
} else {
return $data['reason'];
}
}
return $array;
} catch (ConnectException $e) {
//Logging::error($e);
return null;
}
}
在我的控制器中,我做了
$cpeCountUrl = $ip.':'.$port.'/devices/all.count';
$deviceCountUrl = $ip.':'.$port.'/devices/all.count';
$nodeRegistrationsUrl = $ip.':'.$port.'/registrations';
$promises = [];
$promises['cpeCount'] = $cpeCountUrl;
$promises['deviceCount'] = $deviceCountUrl;
$promises['nodeRegistrations'] = $nodeRegistrationsUrl;
$responses = HTTP::getAsync($promises);
//dd($responses);
$cpeCount = $responses['cpeCount']['data']['Count_of_devices'];
$deviceCount = $responses['deviceCount']['data'];
$totalDeviceCount = $deviceCount['Count_of_devices'];
$activeDeviceCount = $deviceCount['Count_of_active'];
一切正常,一切正常,如何测试或证明我的3个请求同时开始?
在Guzzle中是否可以使用tool
,site
,app
来测试或验证requestAsync()
?