PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_pconn_kill.php

http://github.com/facebook/hiphop-php
PHP | 96 lines | 77 code | 19 blank | 0 comment | 23 complexity | 508f503813ac6100a4502358c193ed34 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. include "connect.inc";
  3. include "table.inc";
  4. if ($socket)
  5. $myhost = sprintf("%s:%s", $host, $socket);
  6. else if ($port)
  7. $myhost = sprintf("%s:%s", $host, $port);
  8. else
  9. $myhost = $host;
  10. if (!($plink = mysql_pconnect($myhost, $user, $passwd)))
  11. printf("[001] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  12. $host, $myhost, $user, $db, $port, $socket);
  13. mysql_select_db($db, $plink);
  14. $pthread_id = mysql_thread_id($plink);
  15. $thread_id = mysql_thread_id($link);
  16. if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
  17. printf("[002] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
  18. $processlist = array();
  19. while ($row = mysql_fetch_assoc($res))
  20. $processlist[$row['Id']] = $row;
  21. mysql_free_result($res);
  22. if (!isset($processlist[$thread_id]))
  23. printf("[003] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  24. if (!isset($processlist[$pthread_id]))
  25. printf("[004] Cannot find persistent connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  26. if (!mysql_query(sprintf("KILL %d", $pthread_id), $link))
  27. printf("[005] Cannot kill persistent connection thread, [%d] %s\n", mysql_errno($link), mysql_error($link));
  28. while (1) {
  29. if (!($res = mysql_query("SHOW FULL PROCESSLIST", $link)))
  30. printf("[006] Cannot get processlist, [%d] %s\n", mysql_errno($link), mysql_error($link));
  31. $processlist2 = array();
  32. while ($row = mysql_fetch_assoc($res))
  33. $processlist2[$row['Id']] = $row;
  34. mysql_free_result($res);
  35. if (isset($processlist2[$pthread_id])) {
  36. sleep(1);
  37. } else {
  38. break;
  39. }
  40. }
  41. if (!isset($processlist2[$thread_id]))
  42. printf("[007] Cannot find regular connection thread in process list, [%d] %s\n", mysql_errno($link), mysql_error($link));
  43. mysql_close($plink);
  44. if (!($plink = @mysql_pconnect($myhost, $user, $passwd)))
  45. printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error());
  46. mysql_select_db($db, $plink);
  47. if (!($res = mysql_query("SELECT 1", $plink)))
  48. printf("[010] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
  49. mysql_free_result($res);
  50. var_dump(mysql_ping($plink));
  51. if (!($res = mysql_query("SELECT 1", $plink)))
  52. printf("[011] Cannot run query on new persistent connection, [%d] %s\n", @mysql_errno($plink), @mysql_error($plink));
  53. mysql_free_result($res);
  54. if (!($link2 = mysql_connect($myhost, $user, $passwd, true)))
  55. printf("[012] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  56. $host, $myhost, $user, $db, $port, $socket);
  57. mysql_select_db($db, $link2);
  58. if (!mysql_query(sprintf("KILL %d", $thread_id), $link2))
  59. printf("[013] Cannot kill regular connection thread, [%d] %s\n", mysql_errno($link2), mysql_error($link2));
  60. if (!($link = mysql_connect($myhost, $user, $passwd, true)))
  61. printf("[014] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  62. $host, $myhost, $user, $db, $port, $socket);
  63. mysql_select_db($db, $link);
  64. if (!($res = mysql_query("SELECT * FROM test", $link)))
  65. printf("[015] Cannot run query on new regular connection, [%d] %s\n", @mysql_errno($link), @mysql_error($link));
  66. if (!($res = mysql_query("SELECT * FROM test", $link2)))
  67. printf("[016] Cannot run query on other regular connection, [%d] %s\n", @mysql_errno($link2), @mysql_error($link2));
  68. mysql_free_result($res);
  69. mysql_close($plink);
  70. mysql_close($link);
  71. mysql_close($link2);
  72. print "done!";
  73. ?>
  74. <?php error_reporting(0); ?>
  75. <?php
  76. require_once("clean_table.inc");
  77. ?>