MySQLi Tutorial MySQLi References

mysqli poll() Method



The mysqli::poll() / mysqli_poll() function is used for poll connections. The method can be used as static.

Note: Available only with mysqlnd.

Syntax

//Object-oriented style
public mysqli::poll(read, error, reject, seconds, microseconds)

//Procedural style
mysqli_poll(mysql, read, error, reject, seconds, microseconds)

Parameters

mysql Required. For procedural style only: Specify a mysqli object returned by mysqli_connect() or mysqli_init().
read Required. Specify list of connections to check for outstanding results that can be read.
error Required. Specify list of connections on which an error occurred. For example - query failure or lost connection.
reject Required. Specify list of connections rejected because no asynchronous query has been run on for which the function could poll results.
seconds Required. Specify maximum number of seconds to wait. It must be non-negative.
microseconds Optional. Specify maximum number of microseconds to wait. It must be non-negative.

Return Value

Returns number of ready connections upon success, false otherwise.

Example: mysqli_poll() example

The example below shows the usage of mysqli_poll() 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
)

❮ MySQLi Functions Reference