1--TEST--
2mysqli_reap_async_query()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('connect.inc');
8require_once('skipifconnectfailure.inc');
9
10if (!$IS_MYSQLND)
11    die("skip mysqlnd only feature, compile PHP using --with-mysqli=mysqlnd");
12?>
13--FILE--
14<?php
15    require_once('connect.inc');
16
17    function get_connection() {
18        global $host, $user, $passwd, $db, $port, $socket;
19
20        if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
21            printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
22        return $link;
23    }
24
25    if (!$link = get_connection())
26        printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
27
28
29    function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {
30
31        if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 50 * 1000)))
32            printf("[%03d + 1] There should be %d links ready to read from, %d ready\n",
33                $offset, $exp_ready, $tmp);
34
35        foreach ($links as $mysqli) {
36            if ($use_oo_syntax) {
37                $res = $mysqli->reap_async_query();
38            } else {
39                $res = mysqli_reap_async_query($mysqli);
40            }
41            if (is_object($res)) {
42                printf("[%03d + 2] %s\n", $offset, var_export($res->fetch_assoc(), true));
43            } else if (mysqli_errno($mysqli) > 0) {
44                printf("[%03d + 3] Error indicated through links array: %d/%s",
45                    $offset, mysqli_errno($mysqli), mysqli_error($mysqli));
46            } else {
47                printf("[%03d + 4] Cannot fetch and no error set - non resultset query (no SELECT)!\n", $offset);
48            }
49        }
50
51        foreach ($errors as $mysqli)
52            printf("[%03d + 5] Error on %d: %d/%s\n",
53                $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
54
55        foreach ($reject as $mysqli)
56            printf("[%03d + 6] Rejecting thread %d: %d/%s\n",
57                $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
58
59    }
60
61    // Connections on which no query has been send - 1
62    $link = get_connection();
63    $link->query("SELECT 1 AS _one", MYSQLI_ASYNC | MYSQLI_STORE_RESULT);
64    $links = array($link);
65    $errors = array($link);
66    $reject = array($link);
67    poll_async(12, $link, $links, $errors, $reject, 1, false);
68    mysqli_close($link);
69
70    $link = get_connection();
71    $link->query("SELECT 2 AS _two", MYSQLI_ASYNC | MYSQLI_USE_RESULT);
72    $links = array($link);
73    $errors = array($link);
74    $reject = array($link);
75    poll_async(13, $link, $links, $errors, $reject, 1, true);
76    mysqli_close($link);
77
78    print "done!";
79?>
80--EXPECT--
81[012 + 2] array (
82  '_one' => '1',
83)
84[013 + 2] array (
85  '_two' => '2',
86)
87done!
88