It is worth to note that example from this docs will results in waiting for all queries to be executed before you can reap your results.
5 years ago bishop from php.net has posted solution that allow to fetch results of each query immediately after executed. For some reason this has never been merged to php manual.
https://bugs.php.net/bug.php?id=70505
The documentation for mysqli_poll suggests iterating through the links after running the poll:
foreach ($links as $link) {
if ($result = $link->reap_async_query()) {
print_r($result->fetch_row());
if (is_object($result))
mysqli_free_result($result);
} else die(sprintf("MySQLi Error: %s", mysqli_error($link)));
$processed++;
}
This is not a good way to go about it when you have queries of different run-times, because mysqli_reap_async_query() blocks until the query resolves, which is contrary to the nature of the async poll.
An approach that respects multiple queries of different run times is to run a reaping function over each of the modified arrays:
$count = mysqli_poll($read, $error, $reject, 1);
if (0 < $count) {
array_walk($read, 'reap');
array_walk($error, 'reap');
array_walk($reject, 'reap');
}
function reap($link) {
$result = mysqli_reap_async_query($link);
if (is_object($result)) {
print_r($result->fetch_assoc()));
mysqli_free_result($result);
} else if (false !== $result) {
print_r($link);
} else {
die(mysqli_error($link));
}
}
This also handles the case where the query is a CRUD and the result of reap_async_query isn't a result object.