Annotation of embedaddon/php/ext/mysqli/tests/mysqli_poll.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: int mysqli_poll() simple
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifemb.inc');
7: require_once('connect.inc');
8: require_once('skipifconnectfailure.inc');
9:
10: if (!$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: if (NULL !== ($tmp = @mysqli_poll()))
29: printf("[002] Expecting NULL got %s\n", var_export($tmp, true));
30:
31: $l = array($link);
32: if (NULL !== ($tmp = @mysqli_poll($l)))
33: printf("[003] Expecting NULL got %s\n", var_export($tmp, true));
34:
35: $l = array($link); $n = NULL;
36: if (NULL !== ($tmp = @mysqli_poll($l, $n)))
37: printf("[004] Expecting NULL got %s\n", var_export($tmp, true));
38:
39: $l = array($link); $n = NULL;
40: if (NULL !== ($tmp = @mysqli_poll($l, $n, $n)))
41: printf("[005] Expecting NULL got %s\n", var_export($tmp, true));
42:
43: $l = array($link); $e = NULL; $r = NULL;
44: if (NULL !== ($tmp = @mysqli_poll($l, $e, $r, -1)))
45: printf("[007] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
46:
47: $l = array($link); $e = NULL; $r = NULL;
48: if (NULL !== ($tmp = @mysqli_poll($l, $e, $r, 0, -1)))
49: printf("[008] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
50:
51: $read = $error = $reject = array($link);
52: if (0 !== ($tmp = (mysqli_poll($read, $error, $reject, 0, 1))))
53: printf("[009] Expecting int/0 got %s/%s\n", gettype($tmp), var_export($tmp, true));
54:
55:
56: function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {
57:
58: if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 1000)))
59: printf("[%03d + 1] There should be %d links ready to read from, %d ready\n",
60: $exp_ready, $tmp);
61:
62: foreach ($links as $mysqli) {
63: if ($use_oo_syntax) {
64: $res = $mysqli->reap_async_query();
65: } else {
66: $res = mysqli_reap_async_query($mysqli);
67: }
68: if (is_object($res)) {
69: printf("[%03d + 2] Can fetch resultset although no query has been run!\n", $offset);
70: } else if (mysqli_errno($mysqli) > 0) {
71: printf("[%03d + 3] Error indicated through links array: %d/%s",
72: $offset, mysqli_errno($mysqli), mysqli_error($mysqli));
73: } else {
74: printf("[%03d + 4] Cannot fetch and no error set - non resultset query (no SELECT)!\n", $offset);
75: }
76: }
77:
78: foreach ($errors as $mysqli)
79: printf("[%03d + 5] Error on %d: %d/%s\n",
80: $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
81:
82: foreach ($reject as $mysqli)
83: printf("[%03d + 6] Rejecting thread %d: %d/%s\n",
84: $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
85:
86: }
87:
88: // Connections on which no query has been send - 1
89: $link = get_connection();
90: $links = array($link);
91: $errors = array($link);
92: $reject = array($link);
93: poll_async(10, $link, $links, $errors, $reject, 0, false);
94: mysqli_close($link);
95:
96: $link = get_connection();
97: $links = array($link);
98: $errors = array($link);
99: $reject = array($link);
100: poll_async(11, $link, $links, $errors, $reject, 0, true);
101: mysqli_close($link);
102:
103: // Connections on which no query has been send - 2
104: // Difference: pass $links twice
105: $link = get_connection();
106: $links = array($link, $link);
107: $errors = array($link, $link);
108: $reject = array();
109: poll_async(12, $link, $links, $errors, $reject, 0, false);
110:
111: // Connections on which no query has been send - 3
112: // Difference: pass two connections
113: $link = get_connection();
114: $links = array($link, get_connection());
115: $errors = array($link, $link);
116: $reject = array();
117: poll_async(13, $link, $links, $errors, $reject, 0, false);
118:
119: // Reference mess...
120: $link = get_connection();
121: $links = array($link);
122: $errors = array($link);
123: $ref_errors =& $errors;
124: $reject = array();
125: poll_async(14, $link, $links, $ref_errors, $reject, 0, false);
126:
127: print "done!";
128: ?>
129: --EXPECTF--
130: [010 + 6] Rejecting thread %d: 0/
131: [011 + 6] Rejecting thread %d: 0/
132: [012 + 6] Rejecting thread %d: 0/
133: [012 + 6] Rejecting thread %d: 0/
134: [013 + 6] Rejecting thread %d: 0/
135: [013 + 6] Rejecting thread %d: 0/
136: [014 + 6] Rejecting thread %d: 0/
137: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>