File: mysqli_reap_async_query.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (79 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--TEST--
mysqli_reap_async_query()
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
    require_once 'connect.inc';

    function get_connection() {
        global $host, $user, $passwd, $db, $port, $socket;

        if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
            printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
        return $link;
    }

    function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {

        if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 50 * 1000)))
            printf("[%03d + 1] There should be %d links ready to read from, %d ready\n",
                $offset, $exp_ready, $tmp);

        foreach ($links as $mysqli) {
            if ($use_oo_syntax) {
                $res = $mysqli->reap_async_query();
            } else {
                $res = mysqli_reap_async_query($mysqli);
            }
            if (is_object($res)) {
                printf("[%03d + 2] %s\n", $offset, var_export($res->fetch_assoc(), true));
            } else if (mysqli_errno($mysqli) > 0) {
                printf("[%03d + 3] Error indicated through links array: %d/%s",
                    $offset, mysqli_errno($mysqli), mysqli_error($mysqli));
            } else {
                printf("[%03d + 4] Cannot fetch and no error set - non resultset query (no SELECT)!\n", $offset);
            }
        }

        foreach ($errors as $mysqli)
            printf("[%03d + 5] Error on %d: %d/%s\n",
                $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));

        foreach ($reject as $mysqli)
            printf("[%03d + 6] Rejecting thread %d: %d/%s\n",
                $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));

    }

    // Connections on which no query has been sent - 1
    $link = get_connection();
    $link->query("SELECT 1 AS _one", MYSQLI_ASYNC | MYSQLI_STORE_RESULT);
    $links = array($link);
    $errors = array($link);
    $reject = array($link);
    poll_async(12, $link, $links, $errors, $reject, 1, false);
    mysqli_close($link);

    $link = get_connection();
    $link->query("SELECT 2 AS _two", MYSQLI_ASYNC | MYSQLI_USE_RESULT);
    $links = array($link);
    $errors = array($link);
    $reject = array($link);
    poll_async(13, $link, $links, $errors, $reject, 1, true);
    mysqli_close($link);

    print "done!";
?>
--EXPECT--
[012 + 2] array (
  '_one' => '1',
)
[013 + 2] array (
  '_two' => '2',
)
done!