mysqli_get_connection_stats.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. mysqli_get_connection_stats()
  3. --INI--
  4. mysqlnd.collect_statistics="1"
  5. mysqlnd.collect_memory_statistics="1"
  6. --SKIPIF--
  7. <?PHP
  8. require_once('skipif.inc');
  9. require_once('skipifemb.inc');
  10. require_once('skipifconnectfailure.inc');
  11. if (!function_exists('mysqli_get_connection_stats')) {
  12. die("skip only available with mysqlnd");
  13. }
  14. ?>
  15. --FILE--
  16. <?php
  17. $tmp = $link = null;
  18. if (!is_null($tmp = @mysqli_get_connection_stats()))
  19. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  20. if (!is_null($tmp = @mysqli_get_connection_stats($link)))
  21. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  22. require("table.inc");
  23. if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
  24. printf("[003] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
  25. if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
  26. printf("[004] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
  27. foreach ($info as $k => &$v) {
  28. if (strpos($k, "mem_") === 0) {
  29. $v = 0;
  30. }
  31. }
  32. foreach ($info2 as $k => &$v) {
  33. if (strpos($k, "mem_") === 0) {
  34. $v = 0;
  35. }
  36. }
  37. if ($info !== $info2) {
  38. printf("[005] The hashes should be identical except of the memory related fields\n");
  39. var_dump($info);
  40. var_dump($info2);
  41. }
  42. if (!is_array($info = $link->get_connection_stats()) || empty($info))
  43. printf("[006] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
  44. foreach ($info as $k => &$v) {
  45. if (strpos($k, "mem_") === 0) {
  46. $v = 0;
  47. }
  48. }
  49. if ($info !== $info2) {
  50. printf("[007] The hashes should be identical except of the memory related fields\n");
  51. var_dump($info);
  52. var_dump($info2);
  53. }
  54. mysqli_close($link);
  55. require("table.inc");
  56. if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
  57. printf("[008] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
  58. if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
  59. printf("[009] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
  60. // assuming the test is run in a plain-vanilla CLI environment
  61. if ($info === $info2) {
  62. printf("[010] The hashes should not be identical\n");
  63. var_dump($info);
  64. var_dump($info2);
  65. }
  66. print "done!";
  67. ?>
  68. --CLEAN--
  69. <?php
  70. require_once("clean_table.inc");
  71. ?>
  72. --EXPECTF--
  73. done!