forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_cache_materialization_fork_002.phpt
More file actions
98 lines (82 loc) · 2.09 KB
/
user_cache_materialization_fork_002.phpt
File metadata and controls
98 lines (82 loc) · 2.09 KB
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
--TEST--
OPcache user cache should keep nested user objects shared until mutation even with SafeDirectCache properties
--EXTENSIONS--
opcache
pcntl
--SKIPIF--
<?php
if (!function_exists('pcntl_fork')) {
die('skip pcntl_fork() not available');
}
?>
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.user_cache_memory_consumption=32
--FILE--
<?php
class LargePayload
{
public function __construct(
public array $rows,
public string $label,
) {}
}
class WrappedPayload
{
public function __construct(
public LargePayload $payload,
public DateTimeImmutable $timestamp,
) {}
}
function build_rows(): array
{
$rows = [];
for ($i = 0; $i < 12000; $i++) {
$rows[] = [
'id' => $i,
'text' => str_repeat(chr(65 + ($i % 26)), 96),
'flags' => [$i, $i + 1, $i + 2, $i + 3],
];
}
return $rows;
}
$readyFile = sys_get_temp_dir() . '/opcache_user_cache_materialization_nested_' . getmypid() . '.ready';
@unlink($readyFile);
$pid = pcntl_fork();
if ($pid === -1) {
throw new RuntimeException('pcntl_fork() failed');
}
if ($pid === 0) {
$deadline = microtime(true) + 5.0;
while (!file_exists($readyFile)) {
if (microtime(true) >= $deadline) {
fwrite(STDERR, "parent did not signal readiness\n");
exit(1);
}
usleep(1000);
}
$before = memory_get_usage();
$fetched = OPcache\cache_fetch('materialization_nested_payload');
$readOnly = $fetched->timestamp->format(DateTimeInterface::ATOM) . '|' . $fetched->payload->rows[100]['text'];
$afterFetch = memory_get_usage();
$fetched->payload->rows[100]['text'] = 'changed';
$afterMutate = memory_get_usage();
var_dump(($afterFetch - $before) < 262144);
var_dump(($afterMutate - $afterFetch) > 131072);
exit(0);
}
$payload = new WrappedPayload(
new LargePayload(build_rows(), 'nested'),
new DateTimeImmutable('2026-06-15 09:30:00', new DateTimeZone('UTC')),
);
if (!OPcache\cache_store('materialization_nested_payload', $payload)) {
throw new RuntimeException('Failed to store materialization_nested_payload');
}
file_put_contents($readyFile, 'ready');
pcntl_waitpid($pid, $status);
@unlink($readyFile);
?>
--EXPECT--
bool(true)
bool(true)