array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'mysqli.poll.php', 1 => 'mysqli::poll', ), 'up' => array ( 0 => 'class.mysqli.php', 1 => 'mysqli', ), 'prev' => array ( 0 => 'mysqli.ping.php', 1 => 'mysqli::ping', ), 'next' => array ( 0 => 'mysqli.prepare.php', 1 => 'mysqli::prepare', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/mysqli/mysqli/poll.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
mysqli::poll -- mysqli_poll — 轮询连接
面向对象风格
&$read
,&$error
,&$reject
,$seconds
,$microseconds
= 0过程化风格
&$read
,&$error
,&$reject
,$seconds
,$microseconds
= 0轮询连接。此方法是 static 的。
注意:
仅可用于 mysqlnd。
read
要检测是否存在可以读取的结果集的连接的数组。
error
发生错误的,例如:SQL 语句执行失败或者已经断开的 连接的数组。
reject
没有可以读取的结果集的连接 的数组。
seconds
秒为单位的最大等待时间,不可以为负数。
microseconds
微秒为单位的最大等待时间,不可以为负数。
成功执行则返回存在可以读取结果集的连接数量,
否则 false
。
当没有传递 read
和 error
参数时抛出
ValueError 异常。
示例 #1 mysqli_poll() 示例
<?php
$link1 = mysqli_connect();
$link1->query("SELECT 'test'", 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, 1)) {
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));
?>
以上示例会输出:
Array ( [0] => test )