forked from krakjoe/apcu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapc_026.phpt
58 lines (49 loc) · 1.47 KB
/
apc_026.phpt
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
--TEST--
Test TTL expiration with fragmented memory
--SKIPIF--
<?php
require_once(__DIR__ . '/skipif.inc');
if (!function_exists('apcu_inc_request_time')) die('skip APC debug build required');
?>
--INI--
apc.enabled=1
apc.enable_cli=1
apc.use_request_time=1
apc.ttl=1
apc.shm_size=1M
--FILE--
<?php
apcu_store("long_ttl", 123456789, 100);
apcu_store("dummy", str_repeat('x', 11000));
apcu_inc_request_time(2);
// Fill the cache
$i = 1;
while (apcu_exists("dummy")) {
apcu_store("key_small_" . $i, $i, 3);
apcu_store("key_large_" . $i, str_repeat('x', 10000), 1);
$i++;
}
// Expire all large entries
apcu_inc_request_time(2);
// This insertion should trigger an expunge which expires all large entries
var_dump(apcu_store("next_large_entry", str_repeat('x', 10000), 1));
var_dump(apcu_fetch("next_large_entry") === str_repeat('x', 10000));
// Check fragmented state (small entries are present, large entries are not present)
var_dump(apcu_fetch("key_small_1"));
var_dump(apcu_fetch("key_large_1"));
// Expire all small entries
apcu_inc_request_time(2);
// This entry should trigger an expunge which expires all small entries.
// This solves fragmentation which allows this entry to be stored without a full cache wipe.
var_dump(apcu_store("very_large_entry", str_repeat('x', 20000), 1));
var_dump(apcu_fetch("very_large_entry") === str_repeat('x', 20000));
var_dump(apcu_fetch("long_ttl"));
?>
--EXPECT--
bool(true)
bool(true)
int(1)
bool(false)
bool(true)
bool(true)
int(123456789)