我建立了一个测试台:
$l1 = mysqli_connect();
$l2 = mysqli_connect();
$l3 = mysqli_connect();
$s1 = "SELECT CURTIME()";
$s2 = "SELECT * FROM"; // will error #1064
$s3 = "SELECT SLEEP(10), CURTIME()";
mysqli_query($l1, $s1, MYSQLI_ASYNC);
mysqli_query($l2, $s2, MYSQLI_ASYNC);
mysqli_query($l3, $s3, MYSQLI_ASYNC);
$started=time();
for ($x=0; $x<5; $x++) {
$ready=$reject=$errors = array($l1, $l2, $l3);
print "\niteration $x at t+" . (time()-$started) . "\n";
mysqli_poll($ready, $errors, $reject, 3);
print "ready = " . count($ready) . "\n";
foreach($ready as $r) {
$c=mysqli_reap_async_query($r);
print "err=" . mysqli_error($r) . " cnt=" . count($c) . "\n";
};
print "errors = " . count($errors) . "\n";
print "reject = " . count($reject) . "\n";
sleep(4);
}
结果(以 // 为前缀的注释):
iteration 0 at t+0
ready = 1 // appears to be SELECT CURTIME()
err= cnt=1
errors = 0
reject = 0
iteration 1 at t+4
ready = 1 // appears to be SELECT * FROM
err=You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '' at line
1 cnt=1
errors = 0
reject = 1 // appears to be SELECT CURTIME() (results reaped)
iteration 2 at t+8
ready = 1 // appears to be SELECT SLEEP(10) despite 8 seconds elapsed
err= cnt=1
errors = 0
reject = 2 // appears to be SELECT CURTIME() + SELECT * FROM
iteration 3 at t+14
ready = 0
errors = 0
reject = 3
iteration 4 at t+21
ready = 0
errors = 0
reject = 3
即 $reject 正在填充已获得结果的链接,而不是尚未准备好轮询的链接。
尝试使用无效连接,从所有数组中删除该值(未添加到 $reject),