mysqli_poll()-第三个参数是什么? [英] mysqli_poll() - what's the third parameter for?

查看:100
本文介绍了mysqli_poll()-第三个参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在没有任何文档的情况下,超出了函数原型查找mysqli_poll()函数的第三个参数是什么.

In the absence of any documentation beyond a function prototype I'm struggling to find what the the third parameter to the mysqli_poll() function is.

int mysqli_poll ( 
     array &$read , 
     array &$error , 
     array &$reject , 
     int $sec 
     [, int $usec ] )

查看(C)源代码,它似乎在$ reject数组中填充了以下资源...

Looking at the (C) source code, it appears to populate the $reject array with resources where...

CONN_GET_STATE((*p)->data) <= CONN_READY 
   || CONN_GET_STATE((*p)->data) == CONN_QUIT_SENT

这是否意味着与服务器的连接正在关闭/关闭?

Does this mean that the connection to the server is shutting down / shutdown?

还有什么?

是否应该预先填充用于检查断开连接的资源?还是会自动从$ read和$ error中添加它们?

Should it be pre-poplulated with the resources to check for disconnection? Or will they be added automatically from $read and $error?

推荐答案

我建立了一个测试平台:

I built a test rig:

$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);
 }

结果(带//前缀的注释):

Results (annotations prefixed with //):

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会填充有已经获得结果的链接,而不是尚未准备好进行轮询的链接.

i.e. $reject is getting populated with links where the results have been reaped, NOT links which are not yet ready to poll.

尝试使用无效的连接,该值将从所有数组中删除(未添加到$ reject中),

Trying with with an invalid connection, the value is removed from all arrays (not added to $reject),

这篇关于mysqli_poll()-第三个参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆