w3resource

PHP mysqli: reap_async_query() function

mysqli_reap_async_query function / mysqli::reap_async_query

The mysqli_reap_async_query function / mysqli::reap_async_query — Get result from async query

Syntax:

Object oriented style

public mysqli_result mysqli::reap_async_query ( void )

Procedural style

mysqli_result mysqli_reap_async_query ( mysqli $link )

Parameter:

Name Description Required/Optional
link A link identifier returned by mysqli_connect() or mysqli_init() Required for procedural style only and Optional for Object oriented style
mysqli_reap_async_query ( void );

Return value:

Returns mysqli_result in success, FALSE otherwise.

Version: PHP 5, PHP 7

Example:

<?php
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!";
?>

Sample Output:

NULL [006] The queries should have finished already done!

See also

PHP Function Reference

Previous: real_query
Next: refresh



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/mysqli_reap_async_query.php