summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/deprecated/apc.php
blob: 7930432c6b169cb7b42693b47a84e33324e150e2 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php

namespace Safe;

use Safe\Exceptions\ApcException;

/**
 * Retrieves cached information and meta-data from APC's data store.
 *
 * @param string $cache_type If cache_type is "user",
 * information about the user cache will be returned.
 *
 * If cache_type is "filehits",
 * information about which files have been served from the bytecode cache
 * for the current request will be returned. This feature must be enabled at
 * compile time using --enable-filehits.
 *
 * If an invalid or no cache_type is specified, information about
 * the system cache (cached files) will be returned.
 * @param bool $limited If limited is TRUE, the
 * return value will exclude the individual list of cache entries.  This
 * is useful when trying to optimize calls for statistics gathering.
 * @return array Array of cached data (and meta-data)
 * @throws ApcException
 *
 */
function apc_cache_info(string $cache_type = '', bool $limited = false): array
{
    error_clear_last();
    $result = \apc_cache_info($cache_type, $limited);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}


/**
 * apc_cas updates an already existing integer value if the
 * old parameter matches the currently stored value
 * with the value of the new parameter.
 *
 * @param string $key The key of the value being updated.
 * @param int $old The old value (the value currently stored).
 * @param int $new The new value to update to.
 * @throws ApcException
 *
 */
function apc_cas(string $key, int $old, int $new): void
{
    error_clear_last();
    $result = \apc_cas($key, $old, $new);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
}


/**
 * Stores a file in the bytecode cache, bypassing all filters.
 *
 * @param string $filename Full or relative path to a PHP file that will be compiled and stored in
 * the bytecode cache.
 * @param bool $atomic
 * @return mixed Returns TRUE on success.
 * @throws ApcException
 *
 */
function apc_compile_file(string $filename, bool $atomic = true)
{
    error_clear_last();
    $result = \apc_compile_file($filename, $atomic);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}


/**
 * Decreases a stored integer value.
 *
 * @param string $key The key of the value being decreased.
 * @param int $step The step, or value to decrease.
 * @param bool|null $success Optionally pass the success or fail boolean value to
 * this referenced variable.
 * @return int Returns the current value of key's value on success
 * @throws ApcException
 *
 */
function apc_dec(string $key, int $step = 1, ?bool &$success = null): int
{
    error_clear_last();
    $result = \apc_dec($key, $step, $success);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}


/**
 * define is notoriously slow. Since the main benefit of
 * APC is to increase the performance of scripts/applications, this mechanism
 * is provided to streamline the process of mass constant definition. However,
 * this function does not perform as well as anticipated.
 *
 * For a better-performing solution, try the
 * hidef extension from PECL.
 *
 * @param string $key The key serves as the name of the constant set
 * being stored. This key is used to retrieve the
 * stored constants in apc_load_constants.
 * @param array $constants An associative array of constant_name =&gt; value
 * pairs. The constant_name must follow the normal
 * constant naming rules.
 * value must evaluate to a scalar value.
 * @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive;
 * i.e. CONSTANT and Constant
 * represent different values. If this parameter evaluates to FALSE the
 * constants will be declared as case-insensitive symbols.
 * @throws ApcException
 *
 */
function apc_define_constants(string $key, array $constants, bool $case_sensitive = true): void
{
    error_clear_last();
    $result = \apc_define_constants($key, $constants, $case_sensitive);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
}


/**
 * Deletes the given files from the opcode cache.
 *
 * @param mixed $keys The files to be deleted. Accepts a string,
 * array of strings, or an APCIterator
 * object.
 * @return mixed Returns TRUE on success.
 * Or if keys is an array, then
 * an empty array is returned on success, or an array of failed files
 * is returned.
 * @throws ApcException
 *
 */
function apc_delete_file($keys)
{
    error_clear_last();
    $result = \apc_delete_file($keys);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}


/**
 * Removes a stored variable from the cache.
 *
 * @param string|string[]|\APCIterator $key The key used to store the value (with
 * apc_store).
 * @throws ApcException
 *
 */
function apc_delete($key): void
{
    error_clear_last();
    $result = \apc_delete($key);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
}


/**
 * Increases a stored number.
 *
 * @param string $key The key of the value being increased.
 * @param int $step The step, or value to increase.
 * @param bool|null $success Optionally pass the success or fail boolean value to
 * this referenced variable.
 * @return int Returns the current value of key's value on success
 * @throws ApcException
 *
 */
function apc_inc(string $key, int $step = 1, ?bool &$success = null): int
{
    error_clear_last();
    $result = \apc_inc($key, $step, $success);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}


/**
 * Loads a set of constants from the cache.
 *
 * @param string $key The name of the constant set (that was stored with
 * apc_define_constants) to be retrieved.
 * @param bool $case_sensitive The default behaviour for constants is to be declared case-sensitive;
 * i.e. CONSTANT and Constant
 * represent different values. If this parameter evaluates to FALSE the
 * constants will be declared as case-insensitive symbols.
 * @throws ApcException
 *
 */
function apc_load_constants(string $key, bool $case_sensitive = true): void
{
    error_clear_last();
    $result = \apc_load_constants($key, $case_sensitive);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
}


/**
 * Retrieves APC's Shared Memory Allocation information.
 *
 * @param bool $limited When set to FALSE (default) apc_sma_info will
 * return a detailed information about each segment.
 * @return array Array of Shared Memory Allocation data; FALSE on failure.
 * @throws ApcException
 *
 */
function apc_sma_info(bool $limited = false): array
{
    error_clear_last();
    $result = \apc_sma_info($limited);
    if ($result === false) {
        throw ApcException::createFromPhpError();
    }
    return $result;
}