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