mysqli_pconn_kill.phpt 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --TEST--
  2. Killing a persistent connection.
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  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. @mysqli_close($plink);
  54. if (!$plink = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  55. printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  56. $host, $user, $db, $port, $socket);
  57. if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) {
  58. printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink));
  59. }
  60. @mysqli_free_result($res3);
  61. @mysqli_close($plink);
  62. mysqli_close($link);
  63. // remove the "p:<host>" from the host variable
  64. $host = substr($host, 2);
  65. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  66. printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  67. $host, $user, $db, $port, $socket);
  68. if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1'))
  69. printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  70. mysqli_free_result($res4);
  71. mysqli_close($link);
  72. print "done!";
  73. ?>
  74. --CLEAN--
  75. <?php
  76. require_once("clean_table.inc");
  77. ?>
  78. --EXPECTF--
  79. done!