mysql_pconn_kill.phpt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --TEST--
  2. mysql_pconnect() - killing persitent connection
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --INI--
  9. mysql.allow_persistent=1
  10. mysql.max_persistent=2
  11. --FILE--
  12. <?php
  13. include "connect.inc";
  14. include "table.inc";
  15. if ($socket)
  16. $myhost = sprintf("%s:%s", $host, $socket);
  17. else if ($port)
  18. $myhost = sprintf("%s:%s", $host, $port);
  19. else
  20. $myhost = $host;
  21. if (!($plink = mysql_pconnect($myhost, $user, $passwd)))
  22. printf("[001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  23. $host, $myhost, $user, $db, $port, $socket);
  24. mysql_select_db($db, $plink);
  25. $pthread_id = mysql_thread_id($plink);
  26. $thread_id = mysql_thread_id($link);
  27. if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
  28. printf("[002] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
  29. $processlist = array();
  30. while ($row = mysql_fetch_assoc($res))
  31. $processlist[$row['Id']] = $row;
  32. mysql_free_result($res);
  33. if (!isset($processlist[$thread_id]))
  34. printf("[003] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  35. if (!isset($processlist[$pthread_id]))
  36. printf("[004] Cannot find persistent connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  37. if (!mysql_query(sprintf("KILL %d", $pthread_id), $link))
  38. printf("[005] Cannot kill persistent connection thread, [%d] %s\n", mysql_errno($link), mysql_error($link));
  39. while (1) {
  40. if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
  41. printf("[006] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
  42. $processlist2 = array();
  43. while ($row = mysql_fetch_assoc($res))
  44. $processlist2[$row['Id']] = $row;
  45. mysql_free_result($res);
  46. if (isset($processlist2[$pthread_id])) {
  47. sleep(1);
  48. } else {
  49. break;
  50. }
  51. }
  52. if (!isset($processlist2[$thread_id]))
  53. printf("[007] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  54. mysql_close($plink);
  55. if (!($plink = @mysql_pconnect($myhost, $user, $passwd)))
  56. printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error());
  57. mysql_select_db($db, $plink);
  58. if (!($res = mysql_query("SELECT 1", $plink)))
  59. printf("[010] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
  60. mysql_free_result($res);
  61. var_dump(mysql_ping($plink));
  62. if (!($res = mysql_query("SELECT 1", $plink)))
  63. printf("[011] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
  64. mysql_free_result($res);
  65. if (!($link2 = mysql_connect($myhost, $user, $passwd, true)))
  66. printf("[012] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  67. $host, $myhost, $user, $db, $port, $socket);
  68. mysql_select_db($db, $link2);
  69. if (!mysql_query(sprintf("KILL %d", $thread_id), $link2))
  70. printf("[013] Cannot kill regular connection thread, [%d] %s\n", mysql_errno($link2), mysql_error($link2));
  71. if (!($link = mysql_connect($myhost, $user, $passwd, true)))
  72. printf("[014] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  73. $host, $myhost, $user, $db, $port, $socket);
  74. mysql_select_db($db, $link);
  75. if (!($res = mysql_query("SELECT * FROM test", $link)))
  76. printf("[015] Cannot run query on new regular connection, [%d] %s\n", @mysql_errno($link), @mysql_error($link));
  77. if (!($res = mysql_query("SELECT * FROM test", $link2)))
  78. printf("[016] Cannot run query on other regular connection, [%d] %s\n", @mysql_errno($link2), @mysql_error($link2));
  79. mysql_free_result($res);
  80. mysql_close($plink);
  81. mysql_close($link);
  82. mysql_close($link2);
  83. print "done!";
  84. ?>
  85. --CLEAN--
  86. <?php
  87. require_once("clean_table.inc");
  88. ?>
  89. --EXPECTF--
  90. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  91. Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  92. bool(true)
  93. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  94. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  95. done!