mysqli_poll.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if (!$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. function get_connection() {
  16. global $host, $user, $passwd, $db, $port, $socket;
  17. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  18. printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  19. return $link;
  20. }
  21. if (!$link = get_connection())
  22. printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  23. if (NULL !== ($tmp = @mysqli_poll()))
  24. printf("[002] Expecting NULL got %s\n", var_export($tmp, true));
  25. $l = array($link);
  26. if (NULL !== ($tmp = @mysqli_poll($l)))
  27. printf("[003] Expecting NULL got %s\n", var_export($tmp, true));
  28. $l = array($link); $n = NULL;
  29. if (NULL !== ($tmp = @mysqli_poll($l, $n)))
  30. printf("[004] Expecting NULL got %s\n", var_export($tmp, true));
  31. $l = array($link); $n = NULL;
  32. if (NULL !== ($tmp = @mysqli_poll($l, $n, $n)))
  33. printf("[005] Expecting NULL got %s\n", var_export($tmp, true));
  34. $l = array($link); $e = NULL; $r = NULL;
  35. if (NULL !== ($tmp = @mysqli_poll($l, $e, $r, -1)))
  36. printf("[007] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
  37. $l = array($link); $e = NULL; $r = NULL;
  38. if (NULL !== ($tmp = @mysqli_poll($l, $e, $r, 0, -1)))
  39. printf("[008] Expecting boolean/false got %s/%s\n", gettype($tmp), var_export($tmp, true));
  40. $read = $error = $reject = array($link);
  41. if (0 !== ($tmp = (mysqli_poll($read, $error, $reject, 0, 1))))
  42. printf("[009] Expecting int/0 got %s/%s\n", gettype($tmp), var_export($tmp, true));
  43. $read = $error = $reject = array($link);
  44. if (false !== ($tmp = (mysqli_poll($read, $error, $reject, -1, 1))))
  45. printf("[010] Expecting false got %s/%s\n", gettype($tmp), var_export($tmp, true));
  46. $read = $error = $reject = array($link);
  47. if (false !== ($tmp = (mysqli_poll($read, $error, $reject, 0, -1))))
  48. printf("[011] Expecting false got %s/%s\n", gettype($tmp), var_export($tmp, true));
  49. function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {
  50. if ($exp_ready !== ($tmp = mysqli_poll($links, $errors, $reject, 0, 1000)))
  51. printf("[%03d + 1] There should be %d links ready to read from, %d ready\n",
  52. $exp_ready, $tmp);
  53. foreach ($links as $mysqli) {
  54. if ($use_oo_syntax) {
  55. $res = $mysqli->reap_async_query();
  56. } else {
  57. $res = mysqli_reap_async_query($mysqli);
  58. }
  59. if (is_object($res)) {
  60. printf("[%03d + 2] Can fetch resultset although no query has been run!\n", $offset);
  61. } else if (mysqli_errno($mysqli) > 0) {
  62. printf("[%03d + 3] Error indicated through links array: %d/%s",
  63. $offset, mysqli_errno($mysqli), mysqli_error($mysqli));
  64. } else {
  65. printf("[%03d + 4] Cannot fetch and no error set - non resultset query (no SELECT)!\n", $offset);
  66. }
  67. }
  68. foreach ($errors as $mysqli)
  69. printf("[%03d + 5] Error on %d: %d/%s\n",
  70. $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
  71. foreach ($reject as $mysqli)
  72. printf("[%03d + 6] Rejecting thread %d: %d/%s\n",
  73. $offset, mysqli_thread_id($mysqli), mysqli_errno($mysqli), mysqli_error($mysqli));
  74. }
  75. // Connections on which no query has been send - 1
  76. $link = get_connection();
  77. $links = array($link);
  78. $errors = array($link);
  79. $reject = array($link);
  80. poll_async(12, $link, $links, $errors, $reject, 0, false);
  81. mysqli_close($link);
  82. $link = get_connection();
  83. $links = array($link);
  84. $errors = array($link);
  85. $reject = array($link);
  86. poll_async(13, $link, $links, $errors, $reject, 0, true);
  87. mysqli_close($link);
  88. // Connections on which no query has been send - 2
  89. // Difference: pass $links twice
  90. $link = get_connection();
  91. $links = array($link, $link);
  92. $errors = array($link, $link);
  93. $reject = array();
  94. poll_async(14, $link, $links, $errors, $reject, 0, false);
  95. // Connections on which no query has been send - 3
  96. // Difference: pass two connections
  97. $link = get_connection();
  98. $links = array($link, get_connection());
  99. $errors = array($link, $link);
  100. $reject = array();
  101. poll_async(15, $link, $links, $errors, $reject, 0, false);
  102. // Reference mess...
  103. $link = get_connection();
  104. $links = array($link);
  105. $errors = array($link);
  106. $ref_errors =& $errors;
  107. $reject = array();
  108. poll_async(16, $link, $links, $ref_errors, $reject, 0, false);
  109. print "done!";
  110. ?>
  111. --EXPECTF--
  112. Warning: mysqli_poll(): Negative values passed for sec and/or usec in %s on line %d
  113. Warning: mysqli_poll(): Negative values passed for sec and/or usec in %s on line %d
  114. [012 + 6] Rejecting thread %d: 0/
  115. [013 + 6] Rejecting thread %d: 0/
  116. [014 + 6] Rejecting thread %d: 0/
  117. [014 + 6] Rejecting thread %d: 0/
  118. [015 + 6] Rejecting thread %d: 0/
  119. [015 + 6] Rejecting thread %d: 0/
  120. [016 + 6] Rejecting thread %d: 0/
  121. done!