summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_get_cache_stats.phpt
blob: 6f068f9227d9944f8b8daf9a62594ec3fd61c2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
--TEST--
mysqli_get_cache_stats()
--SKIPIF--
<?PHP
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_get_cache_stats')) {
	die("skip only available with mysqlnd");
}
if (ini_get("unicode.semantics")) {
	die("skip: zval cache works now only in non-unicode mode");
}
?>
--FILE--
<?php
	$tmp = $link = null;
	if (!is_null($tmp = @mysqli_get_cache_stats($link)))
		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

	include "connect.inc";

	if (!is_array($info = mysqli_get_cache_stats()) || empty($info))
		printf("[002] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);

	var_dump($info);

	if ($info['size'] !== $info['free_items'])
		printf("[003] Unused cache should have size (%d) == free_items (%d)\n",
			$info['size'], $info['free_items']);

	require_once('table.inc');

	if (!is_array($new_info = mysqli_get_cache_stats()) || empty($new_info))
		printf("[004] Expecting array/any_non_empty, got %s/%s\n", gettype($new_info), $new_info);

	if ($info['size'] !== $new_info['size'])
		printf("[005] Cache size should not have changes! Expecting int/%d, got %s/%d\n",
			$info['size'], gettype($new_info['size']), $new_info['size']);

	if (count($info) != count($new_info)) {
		printf("[006] Both arrays should have the same number of entries\n");
		var_dump($info);
		var_dump($new_info);
	}

	if (!$res = mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id"))
		printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

	if (!is_object($res = mysqli_use_result($link)))
		printf("[008] Expecting object, got %s/%s. [%d] %s\n",
			gettype($res), $res, mysqli_errno($link), mysqli_error($link));

	if (!$row = mysqli_fetch_assoc($res))
		printf("[009] There should be at least one row in the test table for this test, [%d] %s\n",
			mysqli_errno($link), mysqli_error($link));

	if (!is_array($new_info = mysqli_get_cache_stats()) || empty($new_info))
		printf("[010] Expecting array/any_non_empty, got %s/%s\n", gettype($new_info), $new_info);

	if ($new_info['get_hits'] <= $info['get_hits'])
		printf("[011] get_hits should have increased, %d (new) <= %d (old)!\n",
			$new_info['get_hits'], $info['get_hits']);

	if (!$row = mysqli_fetch_assoc($res))
		printf("[012] There should be two rows in the test table for this test, [%d] %s\n",
			mysqli_errno($link), mysqli_error($link));

	if (!is_array($new_info = mysqli_get_cache_stats()) || empty($new_info))
		printf("[013] Expecting array/any_non_empty, got %s/%s\n", gettype($new_info), $new_info);

	if ($new_info['put_misses'] <= $info['put_misses'])
		printf("[014] put_misses should have increased, %d (new) <= %d (old)!\n",
			$new_info['put_misses'], $info['put_misses']);

	if ($new_info['references'] < $info['references'] + 2)
		printf("[015] reference counter should have increased, %d (new) < %d + 2 (old)!\n",
			$new_info['references'], $info['references']);

	unset($row);
	mysqli_free_result($res);

	if (!is_array($info = mysqli_get_cache_stats()) || empty($info))
		printf("[016] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);

	if ($info['free_items'] <= $new_info['free_items'])
		printf("[017] Looks like cached entries never get free'd.\n");

	mysqli_close($link);

	print "done!";
?>
--EXPECTF--
array(7) {
  ["put_hits"]=>
  int(0)
  ["put_misses"]=>
  int(0)
  ["get_hits"]=>
  int(0)
  ["get_misses"]=>
  int(0)
  ["size"]=>
  int(%d)
  ["free_items"]=>
  int(%d)
  ["references"]=>
  int(%d)
}
done!
--UEXPECTF--
array(7) {
  [u"put_hits"]=>
  int(0)
  [u"put_misses"]=>
  int(0)
  [u"get_hits"]=>
  int(0)
  [u"get_misses"]=>
  int(0)
  [u"size"]=>
  int(%d)
  [u"free_items"]=>
  int(%d)
  [u"references"]=>
  int(%d)
}
done!