2
int mysqli_poll(array read_links, array write_links, array errors, int timeout_seconds [, int timeout_microseconds])
5
require_once('skipif.inc');
6
require_once('skipifemb.inc');
7
require_once('connect.inc');
10
die("skip mysqlnd only feature, compile PHP using --with-mysqli=mysqlnd");
14
require_once('connect.inc');
16
function get_connection() {
17
global $host, $user, $passwd, $db, $port, $socket;
19
if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
20
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
24
if (!$link = get_connection())
25
printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
27
if (NULL !== ($tmp = @mysqli_poll()))
28
printf("[002] Expecting NULL got %s\n", var_export($tmp, true));
30
if (NULL !== ($tmp = @mysqli_poll(array($link))))
31
printf("[003] Expecting NULL got %s\n", var_export($tmp, true));
33
if (NULL !== ($tmp = @mysqli_poll(array($link), NULL)))
34
printf("[004] Expecting NULL got %s\n", var_export($tmp, true));
36
if (NULL !== ($tmp = @mysqli_poll(array($link), NULL, array($link))))
37
printf("[004a] Expecting NULL got %s\n", var_export($tmp, true));
41
if (NULL !== ($tmp = @mysqli_poll(array($link), $errors, 2)))
42
printf("[005] Expecting NULL got %s\n", var_export($tmp, true));
44
if (false !== ($tmp = @mysqli_poll(array($link), NULL, array($link), -1)))
45
printf("[006] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
47
if (false !== ($tmp = @mysqli_poll(array($link), NULL, array($link), 0, -1)))
48
printf("[007] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
50
if (false !== ($tmp = @mysqli_poll(array($link), NULL, array($link), 0, -1)))
51
printf("[008] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
53
if (0 !== ($tmp = (mysqli_poll(array($link), array($link), array($link), 0, 1))))
54
printf("[009] Expecting int/0 got %s/%s\n", gettype($tmp), var_export($tmp, true));
57
$errors = array($link);
58
$reject = array($link);
59
mysqli_kill($link, mysqli_thread_id($link));
60
// Yes, 1 is expected! We have to fetch the reply from the kill!
61
if (1 !== ($tmp = (mysqli_poll(array($link), $errors, $reject, 0, 10000))))
62
printf("[010] Expecting int/1 got %s/%s\n", gettype($tmp), var_export($tmp, true));
64
$link = get_connection();
65
if (true !== ($tmp = mysqli_query($link, "SELECT 1", MYSQLI_ASYNC | MYSQLI_USE_RESULT)))
66
printf("[011] Expecting boolean/true got %s/%s\n", gettype($tmp), var_export($tmp, true));
68
$errors = array($link);
69
$reject = array($link);
70
mysqli_kill($link, mysqli_thread_id($link));
71
if (1 !== ($tmp = (mysqli_poll(array($link), $errors, $reject, 0, 10000))))
72
printf("[012] Expecting int/1 got %s/%s\n", gettype($tmp), var_export($tmp, true));
75
$link = get_connection();
76
$new_links = array($link);
77
$reject = array($link);
78
var_dump(mysqli_poll($new_links, NULL, $reject, 0, 1000));
80
var_dump(count(($reject)));
82
// No read links, only write links
83
require_once('table.inc');
86
'CREATE TABLE IF NOT EXISTS bogus(id INT)',
88
'SELECT * FROM test ORDER BY id ASC LIMIT 2',
89
'INSERT INTO test(id, label) VALUES (100, "z")',
90
'SELECT * FROM test ORDER BY id ASC LIMIT 2',
92
'UPDATE test SET id = 101 WHERE id > 3',
93
'UPDATE_FIX test SET id = 101 WHERE id > 3',
94
'DROP TABLE IF EXISTS bogus',
95
'DELETE FROM test WHERE id = @a',
96
'DELETE FROM test WHERE id = 1',
99
$link = get_connection();
101
mysqli_real_query($link, "DROP PROCEDURE IF EXISTS p");
102
if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) {
104
$queries[] = 'CALL p("myversion", @version)';
109
for ($i = 0; $i < count($queries); $i++) {
111
$link = get_connection();
113
if (true !== ($tmp = mysqli_query($link, $queries[$i], MYSQLI_ASYNC | MYSQLI_USE_RESULT)))
114
printf("[013] Expecting true got %s/%s\n", gettype($tmp), var_export($tmp, true));
116
$links[mysqli_thread_id($link)] = array(
117
'query' => $queries[$i],
119
'processed' => false,
123
$saved_errors = array();
125
$poll_links = $poll_close = $poll_reject = array();
126
foreach ($links as $thread_id => $link) {
127
if (!$link['processed']) {
128
$poll_links[] = $link['link'];
129
$poll_close[] = $link['link'];
130
$poll_reject[] = $link['link'];
133
if (0 == count($poll_links))
136
if (0 == ($num_ready = mysqli_poll($poll_links, $poll_close, $poll_reject, 0, 200000)))
139
if (!empty($poll_close)) {
140
die(var_dump($poll_close));
143
foreach ($poll_links as $link) {
144
$thread_id = mysqli_thread_id($link);
145
$links[$thread_id]['processed'] = true;
147
if (is_object($res = mysqli_reap_async_query($link))) {
149
while ($row = mysqli_fetch_assoc($res)) {
150
// eat up all results
153
mysqli_free_result($res);
155
// either there is no result (no SELECT) or there is an error
156
if (mysqli_errno($link) > 0) {
157
$saved_errors[$thread_id] = mysqli_errno($link);
158
printf("[014] '%s' caused %d\n", $links[$thread_id]['query'], mysqli_errno($link));
166
// Checking if all lines are still usable
167
foreach ($links as $thread_id => $link) {
168
if (isset($saved_errors[$thread_id]) &&
169
$saved_errors[$thread_id] != mysqli_errno($link['link'])) {
170
printf("[015] Error state not saved for query '%s', %d != %d\n", $link['query'],
171
$saved_errors[$thread_id], mysqli_errno($link['link']));
174
if (!$res = mysqli_query($link['link'], 'SELECT * FROM test WHERE id = 100'))
175
printf("[016] Expecting true got %s/%s\n", gettype($tmp), var_export($tmp, true));
176
if (!$row = mysqli_fetch_row($res))
177
printf("[017] Expecting true got %s/%s\n", gettype($tmp), var_export($tmp, true));
179
mysqli_free_result($res);
183
if ($res = mysqli_query($link['link'], "SELECT * FROM test WHERE id = 1")) {
184
$row = mysqli_fetch_assoc($res);
186
mysqli_free_result($res);
189
if ($have_proc && ($res = mysqli_query($link['link'], "SELECT @version as _version"))) {
190
$row = mysqli_fetch_assoc($res);
191
if ($row['_version'] != 'myversion') {
192
printf("[018] Check procedures\n");
194
mysqli_free_result($res);
197
foreach ($links as $link)
198
mysqli_close($link['link']);
204
Warning: mysqli_poll(): All arrays passed are clear in /home/nixnutz/php5/ext/mysqli/tests/mysqli_poll.php on line 66
209
[014] 'SELECT' caused %d
210
[014] 'UPDATE_FIX test SET id = 101 WHERE id > 3' caused %d
211
[014] 'UPDATE test SET id = 101 WHERE id > 3' caused %d
b'\\ No newline at end of file'