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