function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax)
{
    if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 1000))) {
        printf("[%03d + 1] There should be %d links ready to read from, %d ready\n", $offset, $exp_ready, $tmp);
    }
    foreach ($links as $mysqli) {
        if ($use_oo_syntax) {
            $res = $mysqli->reap_async_query();
        } else {
            $res = mysqli_reap_async_query($mysqli);
        }
        if (is_object($res)) {
            printf("[%03d + 2] %s\n", $offset, var_export($res->fetch_assoc(), true));
        } else {
            if (mysqli_errno($mysqli) > 0) {
                printf("[%03d + 3] Error indicated through links array: %d/%s", $offset, mysqli_errno($mysqli), mysqli_error($mysqli));
            } else {
                printf("[%03d + 4] Cannot fetch and no error set - non resultset query (no SELECT)!\n", $offset);
            }
        }
    }
    foreach ($errors as $mysqli) {
        printf("[%03d + 5] Error on %d: %d/%s\n", $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
    }
    foreach ($reject as $mysqli) {
        printf("[%03d + 6] Rejecting thread %d: %d/%s\n", $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
    }
}
var_dump(mysqli_query($mysqli2, "SELECT SLEEP(0.20)", MYSQLI_ASYNC | MYSQLI_USE_RESULT));
$processed = $loops = 0;
$all = array($mysqli1, $mysqli2);
do {
    $loops++;
    if ($loops > 10) {
        printf("[006] The queries should have finished already\n");
        break;
    }
    $links = $errors = $reject = $all;
    ob_start();
    if (0 == ($ready = mysqli_poll($links, $errors, $reject, 0, 50000))) {
        $tmp = ob_get_contents();
        ob_end_clean();
        if ($tmp != '') {
            printf("Expected error:\n%s\n", $tmp);
            break;
        }
        continue;
    }
    foreach ($links as $link) {
        if ($res = mysqli_reap_async_query($link)) {
            mysqli_free_result($res);
        }
        $processed++;
    }
} while ($processed < 2);
$ready = mysqli_poll($links, $errors, $reject, 0, 50000);
mysqli_close($mysqli1);
mysqli_close($mysqli2);
print "done!";
            $poll_reject[] = $link['link'];
        }
    }
    if (0 == count($poll_links)) {
        break;
    }
    if (0 == ($num_ready = mysqli_poll($poll_links, $poll_errors, $poll_reject, 0, 200000))) {
        continue;
    }
    if (!empty($poll_errors)) {
        die(var_dumtest_mysqli_poll_mixing_insert_select_procedure_1($poll_errors));
    }
    foreach ($poll_links as $link) {
        $thread_id = mysqli_thread_id($link);
        $links[$thread_id]['processed'] = true;
        if (is_object($res = mysqli_reap_async_query($link))) {
            // result set object
            while ($row = mysqli_fetch_assoc($res)) {
                // eat up all results
            }
            mysqli_free_result($res);
        } else {
            // either there is no result (no SELECT) or there is an error
            if (mysqli_errno($link) > 0) {
                $saved_errors[$thread_id] = mysqli_errno($link);
                printf("[003] '%s' caused %d\n", $links[$thread_id]['query'], mysqli_errno($link));
            }
        }
    }
} while (true);
// Checking if all lines are still usable