Skip to content

Commit 4ccf9e3

Browse files
committed
fix API
1 parent 37ce480 commit 4ccf9e3

15 files changed

Lines changed: 656 additions & 275 deletions

ext/opcache/opcache.stub.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,57 +83,57 @@ final class VolatileStatic
8383
public function __construct(int $ttl = 0, CacheStrategy $strategy = CacheStrategy::Immediate) {}
8484
}
8585

86-
function volatile_store(string $key, null|bool|int|float|string|array|object $value, int $ttl = 0): bool {}
86+
function volatile_store(string $key, null|bool|int|float|string|array|object $value, int $ttl = 0, bool $throw_on_error = false): bool {}
8787

88-
function volatile_store_array(array $values, int $ttl = 0): bool {}
88+
function volatile_store_array(array $values, int $ttl = 0, bool $throw_on_error = false): bool {}
8989

90-
function volatile_fetch(string $key, null|bool|int|float|string|array|object $default = null): null|bool|int|float|string|array|object {}
90+
function volatile_fetch(string $key, null|bool|int|float|string|array|object $default = null, bool $throw_on_error = false): null|bool|int|float|string|array|object {}
9191

9292
/**
93-
* @return array<string, null|bool|int|float|string|array|object>|null
93+
* @return array<string, null|bool|int|float|string|array|object>|false
9494
*/
95-
function volatile_fetch_array(array $keys, ?array $default = null): ?array {}
95+
function volatile_fetch_array(array $keys, ?array $default = null, bool $throw_on_error = false): array|false {}
9696

97-
function volatile_exists(string $key): bool {}
97+
function volatile_exists(string $key, bool $throw_on_error = false): bool {}
9898

99-
function volatile_lock(string $key, int $lease = 0): bool {}
99+
function volatile_lock(string $key, int $lease = 0, bool $throw_on_error = false): bool {}
100100

101-
function volatile_unlock(string $key): bool {}
101+
function volatile_unlock(string $key, bool $throw_on_error = false): bool {}
102102

103-
function volatile_delete(string $key_or_class): void {}
103+
function volatile_delete(string $key_or_class, bool $throw_on_error = false): bool {}
104104

105-
function volatile_delete_array(array $keys): void {}
105+
function volatile_delete_array(array $keys, bool $throw_on_error = false): bool {}
106106

107-
function volatile_clear(): void {}
107+
function volatile_clear(bool $throw_on_error = false): bool {}
108108

109109
function volatile_cache_info(): StaticCacheInfo {}
110110

111-
function pinned_store(string $key, null|bool|int|float|string|array|object $value): bool {}
111+
function pinned_store(string $key, null|bool|int|float|string|array|object $value, bool $throw_on_error = false): bool {}
112112

113-
function pinned_store_array(array $values): bool {}
113+
function pinned_store_array(array $values, bool $throw_on_error = false): bool {}
114114

115-
function pinned_fetch(string $key, null|bool|int|float|string|array|object $default = null): null|bool|int|float|string|array|object {}
115+
function pinned_fetch(string $key, null|bool|int|float|string|array|object $default = null, bool $throw_on_error = false): null|bool|int|float|string|array|object {}
116116

117117
/**
118-
* @return array<string, null|bool|int|float|string|array|object>|null
118+
* @return array<string, null|bool|int|float|string|array|object>|false
119119
*/
120-
function pinned_fetch_array(array $keys, ?array $default = null): ?array {}
120+
function pinned_fetch_array(array $keys, ?array $default = null, bool $throw_on_error = false): array|false {}
121121

122-
function pinned_exists(string $key): bool {}
122+
function pinned_exists(string $key, bool $throw_on_error = false): bool {}
123123

124-
function pinned_lock(string $key, int $lease = 0): bool {}
124+
function pinned_lock(string $key, int $lease = 0, bool $throw_on_error = false): bool {}
125125

126-
function pinned_unlock(string $key): bool {}
126+
function pinned_unlock(string $key, bool $throw_on_error = false): bool {}
127127

128-
function pinned_delete(string $key_or_class): void {}
128+
function pinned_delete(string $key_or_class, bool $throw_on_error = false): bool {}
129129

130-
function pinned_delete_array(array $keys): void {}
130+
function pinned_delete_array(array $keys, bool $throw_on_error = false): bool {}
131131

132-
function pinned_clear(): void {}
132+
function pinned_clear(bool $throw_on_error = false): bool {}
133133

134-
function pinned_atomic_increment(string $key, int $step = 1): int {}
134+
function pinned_atomic_increment(string $key, int $step = 1, bool $throw_on_error = false): int|false {}
135135

136-
function pinned_atomic_decrement(string $key, int $step = 1): int {}
136+
function pinned_atomic_decrement(string $key, int $step = 1, bool $throw_on_error = false): int|false {}
137137

138138
function pinned_cache_info(): StaticCacheInfo {}
139139

ext/opcache/opcache_arginfo.h

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
OPcache static cache disabled backends report unavailable and store APIs return false
2+
OPcache static cache disabled backends report unavailable and explicit APIs return false by default
33
--EXTENSIONS--
44
opcache
55
--INI--
@@ -12,22 +12,79 @@ opcache.static_cache.pinned_size_mb=0
1212

1313
function dump_info(string $label, OPcache\StaticCacheInfo $info): void
1414
{
15-
echo $label, "\n";
16-
var_dump($info->enabled);
17-
var_dump($info->available);
18-
var_dump($info->startup_failed);
19-
var_dump($info->backend_initialized);
20-
var_dump($info->configured_memory);
21-
var_dump($info->failure_reason);
15+
echo $label, "\n";
16+
var_dump($info->enabled);
17+
var_dump($info->available);
18+
var_dump($info->startup_failed);
19+
var_dump($info->backend_initialized);
20+
var_dump($info->configured_memory);
21+
var_dump($info->failure_reason);
22+
}
23+
24+
function dump_result(string $label, mixed $value): void
25+
{
26+
echo $label, ': ';
27+
var_dump($value);
28+
}
29+
30+
function dump_static_cache_exception(string $label, Closure $callback): void
31+
{
32+
try {
33+
$callback();
34+
echo $label, ": no exception\n";
35+
} catch (OPcache\StaticCacheException $exception) {
36+
echo $label, ': ', get_class($exception), ': ', $exception->getMessage(), "\n";
37+
}
2238
}
2339

2440
dump_info('volatile', OPcache\volatile_cache_info());
2541
dump_info('pinned', OPcache\pinned_cache_info());
2642

27-
var_dump(OPcache\volatile_store('key', 'value'));
28-
var_dump(OPcache\volatile_store_array(['array-key' => 'value']));
29-
var_dump(OPcache\pinned_store('key', 'value'));
30-
var_dump(OPcache\pinned_store_array(['array-key' => 'value']));
43+
dump_result('volatile_store', OPcache\volatile_store('key', 'value'));
44+
dump_result('volatile_store_array', OPcache\volatile_store_array(['array-key' => 'value']));
45+
dump_result('volatile_fetch', OPcache\volatile_fetch('key', 'default'));
46+
dump_result('volatile_fetch_array', OPcache\volatile_fetch_array(['key'], ['key' => 'default']));
47+
dump_result('volatile_exists', OPcache\volatile_exists('key'));
48+
dump_result('volatile_lock', OPcache\volatile_lock('key'));
49+
dump_result('volatile_unlock', OPcache\volatile_unlock('key'));
50+
dump_result('volatile_delete', OPcache\volatile_delete('key'));
51+
dump_result('volatile_delete_array', OPcache\volatile_delete_array(['key']));
52+
dump_result('volatile_clear', OPcache\volatile_clear());
53+
dump_result('pinned_store', OPcache\pinned_store('key', 'value'));
54+
dump_result('pinned_store_array', OPcache\pinned_store_array(['array-key' => 'value']));
55+
dump_result('pinned_fetch', OPcache\pinned_fetch('key', 'default'));
56+
dump_result('pinned_fetch_array', OPcache\pinned_fetch_array(['key'], ['key' => 'default']));
57+
dump_result('pinned_exists', OPcache\pinned_exists('key'));
58+
dump_result('pinned_lock', OPcache\pinned_lock('key'));
59+
dump_result('pinned_unlock', OPcache\pinned_unlock('key'));
60+
dump_result('pinned_delete', OPcache\pinned_delete('key'));
61+
dump_result('pinned_delete_array', OPcache\pinned_delete_array(['key']));
62+
dump_result('pinned_clear', OPcache\pinned_clear());
63+
dump_result('pinned_atomic_increment', OPcache\pinned_atomic_increment('key'));
64+
dump_result('pinned_atomic_decrement', OPcache\pinned_atomic_decrement('key'));
65+
66+
dump_static_cache_exception('volatile_store_throw', static fn () => OPcache\volatile_store('key', 'value', 0, true));
67+
dump_static_cache_exception('volatile_store_array_throw', static fn () => OPcache\volatile_store_array(['array-key' => 'value'], 0, true));
68+
dump_static_cache_exception('volatile_fetch_throw', static fn () => OPcache\volatile_fetch('key', 'default', true));
69+
dump_static_cache_exception('volatile_fetch_array_throw', static fn () => OPcache\volatile_fetch_array(['key'], ['key' => 'default'], true));
70+
dump_static_cache_exception('volatile_exists_throw', static fn () => OPcache\volatile_exists('key', true));
71+
dump_static_cache_exception('volatile_lock_throw', static fn () => OPcache\volatile_lock('key', 0, true));
72+
dump_static_cache_exception('volatile_unlock_throw', static fn () => OPcache\volatile_unlock('key', true));
73+
dump_static_cache_exception('volatile_delete_throw', static fn () => OPcache\volatile_delete('key', true));
74+
dump_static_cache_exception('volatile_delete_array_throw', static fn () => OPcache\volatile_delete_array(['key'], true));
75+
dump_static_cache_exception('volatile_clear_throw', static fn () => OPcache\volatile_clear(true));
76+
dump_static_cache_exception('pinned_store_throw', static fn () => OPcache\pinned_store('key', 'value', true));
77+
dump_static_cache_exception('pinned_store_array_throw', static fn () => OPcache\pinned_store_array(['array-key' => 'value'], true));
78+
dump_static_cache_exception('pinned_fetch_throw', static fn () => OPcache\pinned_fetch('key', 'default', true));
79+
dump_static_cache_exception('pinned_fetch_array_throw', static fn () => OPcache\pinned_fetch_array(['key'], ['key' => 'default'], true));
80+
dump_static_cache_exception('pinned_exists_throw', static fn () => OPcache\pinned_exists('key', true));
81+
dump_static_cache_exception('pinned_lock_throw', static fn () => OPcache\pinned_lock('key', 0, true));
82+
dump_static_cache_exception('pinned_unlock_throw', static fn () => OPcache\pinned_unlock('key', true));
83+
dump_static_cache_exception('pinned_delete_throw', static fn () => OPcache\pinned_delete('key', true));
84+
dump_static_cache_exception('pinned_delete_array_throw', static fn () => OPcache\pinned_delete_array(['key'], true));
85+
dump_static_cache_exception('pinned_clear_throw', static fn () => OPcache\pinned_clear(true));
86+
dump_static_cache_exception('pinned_atomic_increment_throw', static fn () => OPcache\pinned_atomic_increment('key', 1, true));
87+
dump_static_cache_exception('pinned_atomic_decrement_throw', static fn () => OPcache\pinned_atomic_decrement('key', 1, true));
3188

3289
?>
3390
--EXPECT--
@@ -45,7 +102,47 @@ bool(false)
45102
bool(false)
46103
int(0)
47104
NULL
48-
bool(false)
49-
bool(false)
50-
bool(false)
51-
bool(false)
105+
volatile_store: bool(false)
106+
volatile_store_array: bool(false)
107+
volatile_fetch: bool(false)
108+
volatile_fetch_array: bool(false)
109+
volatile_exists: bool(false)
110+
volatile_lock: bool(false)
111+
volatile_unlock: bool(false)
112+
volatile_delete: bool(false)
113+
volatile_delete_array: bool(false)
114+
volatile_clear: bool(false)
115+
pinned_store: bool(false)
116+
pinned_store_array: bool(false)
117+
pinned_fetch: bool(false)
118+
pinned_fetch_array: bool(false)
119+
pinned_exists: bool(false)
120+
pinned_lock: bool(false)
121+
pinned_unlock: bool(false)
122+
pinned_delete: bool(false)
123+
pinned_delete_array: bool(false)
124+
pinned_clear: bool(false)
125+
pinned_atomic_increment: bool(false)
126+
pinned_atomic_decrement: bool(false)
127+
volatile_store_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
128+
volatile_store_array_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
129+
volatile_fetch_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
130+
volatile_fetch_array_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
131+
volatile_exists_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
132+
volatile_lock_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
133+
volatile_unlock_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
134+
volatile_delete_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
135+
volatile_delete_array_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
136+
volatile_clear_throw: OPcache\StaticCacheException: OPcache volatile cache is disabled
137+
pinned_store_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
138+
pinned_store_array_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
139+
pinned_fetch_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
140+
pinned_fetch_array_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
141+
pinned_exists_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
142+
pinned_lock_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
143+
pinned_unlock_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
144+
pinned_delete_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
145+
pinned_delete_array_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
146+
pinned_clear_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
147+
pinned_atomic_increment_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled
148+
pinned_atomic_decrement_throw: OPcache\StaticCacheException: OPcache pinned cache is disabled

ext/opcache/tests/static_cache_explicit_cache_fragmentation_relocation_skip_001.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ function cache_store(string $kind, string $key, mixed $value): bool
3030
return OPcache\volatile_store($key, $value);
3131
}
3232

33-
OPcache\pinned_store($key, $value);
34-
return true;
33+
return OPcache\pinned_store($key, $value);
3534
}
3635

3736
function cache_fetch(string $kind, string $key): mixed
@@ -100,7 +99,7 @@ bool(true)
10099
bool(true)
101100
bool(true)
102101
bool(true)
103-
OPcache\StaticCacheException: not enough shared memory left
102+
bool(false)
104103
bool(false)
105104
int(1200000)
106105
int(1200000)

0 commit comments

Comments
 (0)