PHP Function Reference

PHP mysqli reap_async_query() Method



The PHP mysqli::reap_async_query() / mysqli_reap_async_query() function is used to get result from async query.

Note: Available only with mysqlnd.

Syntax

//Object-oriented style
public mysqli::reap_async_query()

//Procedural style
mysqli_reap_async_query(mysql)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().

Return Value

Returns false on failure. For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN, this function will return a mysqli_result object. For other successful queries, this function will return true.

Example: mysqli_reap_async_query() example

The example below shows the usage of mysqli_reap_async_query() function.

<?php
$link1 = mysqli_connect();
$link1->query("SELECT 'demo'", MYSQLI_ASYNC);
$all_links = array($link1);
$processed = 0;
do {
  $links = $errors = $reject = array();

  foreach ($all_links as $link) {
    $links[] = $errors[] = $reject[] = $link;
  }

  if (!mysqli_poll($links, $errors, $reject, 0, 50000)) {
    continue;
  }

  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++;
  }
} while ($processed < count($all_links));
?>

The output of the above code will be similar to:

Array
(
    [0] => demo
)

❮ PHP MySQLi Reference