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