I'm requesting multiple addresses with different response time:
$urlList = [
'https://httpstat.us/200?sleep=3000',
'https://httpstat.us/200?sleep=1000'
];
$mh = curl_multi_init();
$curlHandlerList = [];
foreach ($urlList as $i => $url) {
$ch = $curlHandlerList[$i] = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
]);
curl_multi_add_handle($mh, $ch);
}
while (CURLM_OK == curl_multi_exec($mh, $active) && $active) {
usleep(10**4); // 10**4 microseconds => 0.01 seconds
curl_multi_select($mh, .01);
}
foreach ($curlHandlerList as $ch) {
$html = curl_multi_getcontent($ch);
echo "$html
";
}
Is it possible to access the output of already completed curl handlers as soon as it happens?