mysqli_pconn_kill.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --TEST--
  2. Killing a persistent connection.
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. require_once("connect.inc");
  9. ?>
  10. --INI--
  11. mysqli.allow_persistent=1
  12. mysqli.max_persistent=2
  13. --FILE--
  14. <?php
  15. require_once("connect.inc");
  16. require_once("table.inc");
  17. $host = 'p:' . $host;
  18. if (!$plink = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  19. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  20. $host, $user, $db, $port, $socket);
  21. // get the thread ids of the two connections...
  22. $thread_id = mysqli_thread_id($link);
  23. $pthread_id = mysqli_thread_id($plink);
  24. if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
  25. printf("[002] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  26. $running_threads = array();
  27. while ($row = mysqli_fetch_assoc($res))
  28. $running_threads[$row['Id']] = $row;
  29. mysqli_free_result($res);
  30. if (count($running_threads) < 2)
  31. printf("[003] Processlist is too short, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  32. if (!isset($running_threads[$thread_id]))
  33. printf("[004] Cannot find thread id of the regular link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  34. if (!isset($running_threads[$pthread_id]))
  35. printf("[005] Cannot find thread id of the persistent link, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  36. // Kill the persistent connection - don't use mysqli_kill, mysqlnd will catch that...
  37. if (!mysqli_query($link, sprintf('KILL %d', $pthread_id)))
  38. printf("[006] Cannot kill persistent connection, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  39. mysqli_close($plink);
  40. // Give the server think-time to kill the pthread
  41. sleep(1);
  42. if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST'))
  43. printf("[007] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  44. $running_threads2 = array();
  45. while ($row = mysqli_fetch_assoc($res))
  46. $running_threads2[$row['Id']] = $row;
  47. mysqli_free_result($res);
  48. if (isset($running_threads2[$pthread_id]))
  49. printf("[008] Thread of the persistent connection should have been gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  50. if (!isset($running_threads2[$thread_id]))
  51. printf("[009] Thread of the regular connection should be still there, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  52. // On PHP side this should do nothing. PHP should not try to close the connection or something.
  53. try {
  54. mysqli_close($plink);
  55. } catch (Error $exception) {
  56. echo $exception->getMessage() . "\n";
  57. }
  58. if (!$plink = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  59. printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  60. $host, $user, $db, $port, $socket);
  61. if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) {
  62. printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink));
  63. }
  64. @mysqli_free_result($res3);
  65. @mysqli_close($plink);
  66. mysqli_close($link);
  67. // remove the "p:<host>" from the host variable
  68. $host = substr($host, 2);
  69. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  70. printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  71. $host, $user, $db, $port, $socket);
  72. if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1'))
  73. printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  74. mysqli_free_result($res4);
  75. mysqli_close($link);
  76. print "done!";
  77. ?>
  78. --CLEAN--
  79. <?php
  80. require_once("clean_table.inc");
  81. ?>
  82. --EXPECT--
  83. mysqli object is already closed
  84. done!