|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of CacheTool. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Samuel Gordalina <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CacheTool\Proxy; |
|
13
|
|
|
|
|
14
|
|
|
use CacheTool\Adapter\AbstractAdapter; |
|
15
|
|
|
use CacheTool\Code; |
|
16
|
|
|
|
|
17
|
|
|
class ApcProxy implements ProxyInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var AbstractAdapter |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $adapter; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function getFunctions() |
|
28
|
|
|
{ |
|
29
|
|
|
return array( |
|
30
|
1 |
|
'apc_add', |
|
31
|
1 |
|
'apc_bin_dump', |
|
32
|
1 |
|
'apc_bin_dumpfile', |
|
33
|
1 |
|
'apc_bin_load', |
|
34
|
1 |
|
'apc_bin_loadfile', |
|
35
|
1 |
|
'apc_cas', |
|
36
|
1 |
|
'apc_cache_info', |
|
37
|
1 |
|
'apc_clear_cache', |
|
38
|
1 |
|
'apc_compile_file', |
|
39
|
1 |
|
'apc_dec', |
|
40
|
1 |
|
'apc_define_constants', |
|
41
|
1 |
|
'apc_delete_file', |
|
42
|
1 |
|
'apc_delete', |
|
43
|
1 |
|
'apc_exists', |
|
44
|
1 |
|
'apc_fetch', |
|
45
|
1 |
|
'apc_inc', |
|
46
|
1 |
|
'apc_load_constants', |
|
47
|
1 |
|
'apc_sma_info', |
|
48
|
1 |
|
'apc_store', |
|
49
|
|
|
|
|
50
|
|
|
'apc_version' |
|
51
|
1 |
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
2 |
|
public function setAdapter(AbstractAdapter $adapter) |
|
58
|
|
|
{ |
|
59
|
2 |
|
$this->adapter = $adapter; |
|
60
|
2 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Caches a variable in the data store, only if it's not already stored |
|
64
|
|
|
* |
|
65
|
|
|
* Note: Unlike many other mechanisms in PHP, variables stored using apc_add() will persist between requests |
|
66
|
|
|
* (until the value is removed from the cache). |
|
67
|
|
|
* |
|
68
|
|
|
* @since 3.0.13 |
|
69
|
|
|
* @param mixed $key Store the variable using this name. keys are cache-unique, so attempting to use apc_add() to |
|
70
|
|
|
* store data with a key that already exists will not overwrite the existing data, and will |
|
71
|
|
|
* instead return FALSE. (This is the only difference between apc_add() and apc_store().) |
|
72
|
|
|
* If $key is an array set Names in key, variables in value |
|
73
|
|
|
* @param mixed $var The variable to store |
|
74
|
|
|
* If $key is an array, this parameter is unused and set to NULL |
|
75
|
|
|
* @param int $ttl Time To Live; store var in the cache for ttl seconds. After the ttl has passed, the stored |
|
76
|
|
|
* variable will be expunged from the cache (on the next request). If no ttl is supplied |
|
77
|
|
|
* (or if the ttl is 0), the value will persist until it is removed from the cache manually, |
|
78
|
|
|
* or otherwise fails to exist in the cache (clear, restart, etc.). |
|
79
|
|
|
* @return mixed |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function apc_add($key, $var = null, $ttl = 0) |
|
82
|
|
|
{ |
|
83
|
2 |
|
if (is_string($key) && $var === null) { |
|
84
|
1 |
|
throw new \InvalidArgumentException('When $key is set $var cannot be null'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
$code = new Code(); |
|
88
|
1 |
|
$code->addStatement(sprintf( |
|
89
|
1 |
|
'return apc_add(%s, %s, %s);', |
|
90
|
1 |
|
var_export($key, true), |
|
91
|
1 |
|
var_export($var, true), |
|
92
|
1 |
|
var_export($ttl, true) |
|
93
|
1 |
|
)); |
|
94
|
|
|
|
|
95
|
1 |
|
return $this->adapter->run($code); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get a binary dump of the given files and user variables |
|
100
|
|
|
* |
|
101
|
|
|
* Returns a binary dump of the given files and user variables from the APC cache. A NULL for files or user_vars |
|
102
|
|
|
* signals a dump of every entry, whereas array() will dump nothing |
|
103
|
|
|
* |
|
104
|
|
|
* @since 3.1.4 |
|
105
|
|
|
* @param mixed $files The files. Passing in NULL signals a dump of every entry, while passing in array() will |
|
106
|
|
|
* dump nothing. |
|
107
|
|
|
* @param mixed $user_vars The user vars. Passing in NULL signals a dump of every entry, while passing in array() |
|
108
|
|
|
* will dump nothing. |
|
109
|
|
|
* @return mixed Returns a binary dump of the given files and user variables from the APC cache, FALSE if |
|
110
|
|
|
* APC is not enabled, or NULL if an unknown error is encountered. |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function apc_bin_dump(array $files = null, $user_vars = null) |
|
113
|
|
|
{ |
|
114
|
1 |
|
$code = new Code(); |
|
115
|
1 |
|
$code->addStatement(sprintf( |
|
116
|
1 |
|
'return apc_bin_dump(%s, %s);', |
|
117
|
1 |
|
var_export($files, true), |
|
118
|
1 |
|
var_export($user_vars, true) |
|
119
|
1 |
|
)); |
|
120
|
|
|
|
|
121
|
1 |
|
return $this->adapter->run($code); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Outputs a binary dump of the given files and user variables from the APC cache to the named file. |
|
126
|
|
|
* |
|
127
|
|
|
* @since 3.1.4 |
|
128
|
|
|
* @param array $files The file names being dumped |
|
129
|
|
|
* @param array $user_vars The user variables being dumped |
|
130
|
|
|
* @param string $filename The filename where the dump is being saved |
|
131
|
|
|
* @param integer $flags Flags passed to the filename stream. See the file_put_contents() documentation for |
|
132
|
|
|
* details. |
|
133
|
|
|
* @param resource $context The context passed to the filename stream. See the file_put_contents() documentation |
|
134
|
|
|
* for details. |
|
135
|
|
|
* @return integer The number of bytes written to the file, otherwise FALSE if APC is not enabled, |
|
136
|
|
|
* filename is an invalid file name, filename can't be opened, the file dump can't be |
|
137
|
|
|
* completed (e.g., the hard drive is out of disk space), or an unknown error was |
|
138
|
|
|
* encountered. |
|
139
|
|
|
*/ |
|
140
|
1 |
|
public function apc_bin_dumpfile(array $files, array $user_vars, $filename, $flags = 0, $context = null) |
|
141
|
|
|
{ |
|
142
|
1 |
|
$code = new Code(); |
|
143
|
1 |
|
$code->addStatement(sprintf( |
|
144
|
1 |
|
'return apc_bin_dumpfile(%s, %s, %s, %s, %s);', |
|
145
|
1 |
|
var_export($files, true), |
|
146
|
1 |
|
var_export($user_vars, true), |
|
147
|
1 |
|
var_export($filename, true), |
|
148
|
1 |
|
var_export($flags, true), |
|
149
|
1 |
|
var_export($context, true) |
|
150
|
1 |
|
)); |
|
151
|
|
|
|
|
152
|
1 |
|
return $this->adapter->run($code); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Loads the given binary dump into the APC file/user cache |
|
157
|
|
|
* |
|
158
|
|
|
* @since 3.1.4 |
|
159
|
|
|
* @param string $data The binary dump being loaded, likely from apc_bin_dump(). |
|
160
|
|
|
* @param integer $flags Either APC_BIN_VERIFY_CRC32, APC_BIN_VERIFY_MD5, or both. |
|
161
|
|
|
* @return boolean Returns TRUE if the binary dump data was loaded with success, otherwise FALSE is returned. |
|
162
|
|
|
* FALSE is returned if APC is not enabled, or if the data is not a valid APC binary dump (e.g., unexpected size) |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function apc_bin_load($data, $flags = 0) |
|
165
|
|
|
{ |
|
166
|
1 |
|
$code = new Code(); |
|
167
|
1 |
|
$code->addStatement(sprintf( |
|
168
|
1 |
|
'return apc_bin_load(%s, %s);', |
|
169
|
1 |
|
var_export($data, true), |
|
170
|
1 |
|
var_export($flags, true) |
|
171
|
1 |
|
)); |
|
172
|
|
|
|
|
173
|
1 |
|
return $this->adapter->run($code); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Load a binary dump from a file into the APC file/user cache |
|
178
|
|
|
* |
|
179
|
|
|
* @since 3.1.4 |
|
180
|
|
|
* @param string $filename The file name containing the dump, likely from apc_bin_dumpfile(). |
|
181
|
|
|
* @param resource $context The files context. |
|
182
|
|
|
* @param integer $flags Either APC_BIN_VERIFY_CRC32, APC_BIN_VERIFY_MD5, or both. |
|
183
|
|
|
* @return boolean Returns TRUE on success, otherwise FALSE Reasons it may return FALSE include APC is not |
|
184
|
|
|
* enabled, filename is an invalid file name or empty, filename can't be opened, the file |
|
185
|
|
|
* dump can't be completed, or if the data is not a valid APC binary dump (e.g., |
|
186
|
|
|
* unexpected size). |
|
187
|
|
|
*/ |
|
188
|
1 |
|
public function apc_bin_loadfile($filename, $context = null, $flags = 0) |
|
189
|
|
|
{ |
|
190
|
1 |
|
$code = new Code(); |
|
191
|
1 |
|
$code->addStatement(sprintf( |
|
192
|
1 |
|
'return apc_bin_loadfile(%s, %s, %s);', |
|
193
|
1 |
|
var_export($filename, true), |
|
194
|
1 |
|
var_export($context, true), |
|
195
|
1 |
|
var_export($flags, true) |
|
196
|
1 |
|
)); |
|
197
|
|
|
|
|
198
|
1 |
|
return $this->adapter->run($code); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Updates an old value with a new value |
|
203
|
|
|
* apc_cas() updates an already existing integer value if the old parameter matches the currently stored value with the value of the new parameter. |
|
204
|
|
|
* |
|
205
|
|
|
* @since 3.1.1 |
|
206
|
|
|
* @param string $key The key of the value being updated. |
|
207
|
|
|
* @param int $old The old value (the value currently stored). |
|
208
|
|
|
* @param int $new The new value to update to |
|
209
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. |
|
210
|
|
|
*/ |
|
211
|
1 |
|
public function apc_cas($key, $old, $new) |
|
212
|
|
|
{ |
|
213
|
1 |
|
$code = new Code(); |
|
214
|
1 |
|
$code->addStatement(sprintf( |
|
215
|
1 |
|
'return apc_cas(%s, %s, %s);', |
|
216
|
1 |
|
var_export($key, true), |
|
217
|
1 |
|
var_export($old, true), |
|
218
|
1 |
|
var_export($new, true) |
|
219
|
1 |
|
)); |
|
220
|
|
|
|
|
221
|
1 |
|
return $this->adapter->run($code); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Retrieves cached information from APC's data store |
|
226
|
|
|
* |
|
227
|
|
|
* @since 2.0.0 |
|
228
|
|
|
* @param string $cache_type If cache_type is "user", information about the user cache will be returned. |
|
229
|
|
|
* If cache_type is "filehits", information about which files have been served from the |
|
230
|
|
|
* bytecode cache for the current request will be returned. This feature must be enabled |
|
231
|
|
|
* at compile time using --enable-filehits . |
|
232
|
|
|
* If an invalid or no cache_type is specified, information about the system cache |
|
233
|
|
|
* (cached files) will be returned. |
|
234
|
|
|
* @param boolean $limited If limited is TRUE, the return value will exclude the individual list of cache |
|
235
|
|
|
* entries. This is useful when trying to optimize calls for statistics gathering. |
|
236
|
|
|
* @return boolean Array of cached data (and meta-data) or FALSE on failure |
|
237
|
|
|
*/ |
|
238
|
1 |
|
public function apc_cache_info($cache_type = "", $limited = false) |
|
239
|
|
|
{ |
|
240
|
1 |
|
$code = new Code(); |
|
241
|
1 |
|
$code->addStatement(sprintf( |
|
242
|
1 |
|
'return apc_cache_info(%s, %s);', |
|
243
|
1 |
|
var_export($cache_type, true), |
|
244
|
1 |
|
var_export($limited, true) |
|
245
|
1 |
|
)); |
|
246
|
|
|
|
|
247
|
1 |
|
return $this->adapter->run($code); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Clears the user/system cache |
|
252
|
|
|
* |
|
253
|
|
|
* @since 2.0.0 |
|
254
|
|
|
* @param string $cache_type If cache_type is "user", the user cache will be cleared; otherwise, the system cache |
|
255
|
|
|
* (cached files) will be cleared. |
|
256
|
|
|
* @return boolean Always returns true |
|
257
|
|
|
*/ |
|
258
|
1 |
|
public function apc_clear_cache($cache_type = "") |
|
259
|
|
|
{ |
|
260
|
1 |
|
$code = new Code(); |
|
261
|
1 |
|
$code->addStatement(sprintf( |
|
262
|
1 |
|
'return apc_clear_cache(%s);', |
|
263
|
1 |
|
var_export($cache_type, true) |
|
264
|
1 |
|
)); |
|
265
|
|
|
|
|
266
|
1 |
|
return $this->adapter->run($code); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Stores a file in the bytecode cache, bypassing all filters. |
|
271
|
|
|
* |
|
272
|
|
|
* @since 3.0.13 |
|
273
|
|
|
* @param string $filename Full or relative path to a PHP file that will be compiled and stored in the bytecode cache. |
|
274
|
|
|
* @param boolean $atomic defaults to true |
|
275
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
|
276
|
|
|
*/ |
|
277
|
1 |
|
public function apc_compile_file($filename, $atomic = true) |
|
278
|
|
|
{ |
|
279
|
1 |
|
$code = new Code(); |
|
280
|
1 |
|
$code->addStatement(sprintf( |
|
281
|
1 |
|
'return apc_compile_file(%s, %s);', |
|
282
|
1 |
|
var_export($filename, true), |
|
283
|
1 |
|
var_export($atomic, true) |
|
284
|
1 |
|
)); |
|
285
|
|
|
|
|
286
|
1 |
|
return $this->adapter->run($code); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Decrease a stored number |
|
291
|
|
|
* |
|
292
|
|
|
* @since 3.1.1 |
|
293
|
|
|
* @param string $key The key of the value being decreased. |
|
294
|
|
|
* @param int $step The step, or value to decrease. |
|
295
|
|
|
* @param \stdClass $ref success is set to TRUE in success and FALSE in failure |
|
296
|
|
|
* @return mixed Returns the current value of key's value on success, or FALSE on failure |
|
297
|
|
|
*/ |
|
298
|
1 |
|
public function apc_dec($key, $step = 1, $ref = false) |
|
299
|
|
|
{ |
|
300
|
1 |
|
$code = new Code(); |
|
301
|
1 |
|
$code->addStatement('$success = false;'); |
|
302
|
1 |
|
$code->addStatement(sprintf( |
|
303
|
1 |
|
'$result = apc_dec(%s, %s, $success);', |
|
304
|
1 |
|
var_export($key, true), |
|
305
|
1 |
|
var_export($step, true) |
|
306
|
1 |
|
)); |
|
307
|
1 |
|
$code->addStatement('return array($result, $success);'); |
|
308
|
|
|
|
|
309
|
1 |
|
list($result, $success) = $this->adapter->run($code); |
|
310
|
|
|
|
|
311
|
1 |
|
if (is_object($ref)) { |
|
312
|
1 |
|
$ref->success = $success; |
|
313
|
1 |
|
} |
|
314
|
|
|
|
|
315
|
1 |
|
return $result; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Defines a set of constants for retrieval and mass-definition |
|
320
|
|
|
* |
|
321
|
|
|
* define() is notoriously slow. Since the main benefit of APC is to increase the performance of |
|
322
|
|
|
* scripts/applications, this mechanism is provided to streamline the process of mass constant definition. However, |
|
323
|
|
|
* this function does not perform as well as anticipated. |
|
324
|
|
|
* |
|
325
|
|
|
* @since 3.0.0 |
|
326
|
|
|
* @param string $key The key serves as the name of the constant set being stored. This key is used to |
|
327
|
|
|
* retrieve the stored constants in apc_load_constants(). |
|
328
|
|
|
* @param array $constants An associative array of constant_name => value pairs. The constant_name must |
|
329
|
|
|
* follow the normal constant naming rules. value must evaluate to a scalar value. |
|
330
|
|
|
* @param boolean $case_sensitive The default behaviour for constants is to be declared case-sensitive; i.e. |
|
331
|
|
|
* CONSTANT and Constant represent different values. If this parameter evaluates to |
|
332
|
|
|
* FALSE the constants will be declared as case-insensitive symbols. |
|
333
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. |
|
334
|
|
|
*/ |
|
335
|
1 |
|
public function apc_define_constants($key, array $constants, $case_sensitive = true) |
|
336
|
|
|
{ |
|
337
|
1 |
|
$code = new Code(); |
|
338
|
1 |
|
$code->addStatement(sprintf( |
|
339
|
1 |
|
'return apc_define_constants(%s, %s, %s);', |
|
340
|
1 |
|
var_export($key, true), |
|
341
|
1 |
|
var_export($constants, true), |
|
342
|
1 |
|
var_export($case_sensitive, true) |
|
343
|
1 |
|
)); |
|
344
|
|
|
|
|
345
|
1 |
|
return $this->adapter->run($code); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Deletes files from the opcode cache |
|
350
|
|
|
* |
|
351
|
|
|
* @since 3.1.1 |
|
352
|
|
|
* @param mixed $keys The files to be deleted. Accepts a string, array of strings, or an APCIterator object. |
|
353
|
|
|
* @return mixed Returns TRUE on success or FALSE on failure. Or if keys is an array, then an empty array is |
|
354
|
|
|
* returned on success, or an array of failed files is returned. |
|
355
|
|
|
*/ |
|
356
|
1 |
|
public function apc_delete_file($keys) |
|
357
|
|
|
{ |
|
358
|
1 |
|
$code = new Code(); |
|
359
|
1 |
|
$code->addStatement(sprintf( |
|
360
|
1 |
|
'return apc_delete_file(%s);', |
|
361
|
1 |
|
var_export($keys, true) |
|
362
|
1 |
|
)); |
|
363
|
|
|
|
|
364
|
1 |
|
return $this->adapter->run($code); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* Removes a stored variable from the cache |
|
369
|
|
|
* |
|
370
|
|
|
* @since 3.1.1 |
|
371
|
|
|
* @param mixed $key The key used to store the value (with apc_store()). |
|
372
|
|
|
* @return mixed Returns TRUE on success or FALSE on failure. |
|
373
|
|
|
*/ |
|
374
|
1 |
|
public function apc_delete($key) |
|
375
|
|
|
{ |
|
376
|
1 |
|
$code = new Code(); |
|
377
|
1 |
|
$code->addStatement(sprintf( |
|
378
|
1 |
|
'return apc_delete(%s);', |
|
379
|
1 |
|
var_export($key, true) |
|
380
|
1 |
|
)); |
|
381
|
|
|
|
|
382
|
1 |
|
return $this->adapter->run($code); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* Checks if one or more APC keys exist. |
|
387
|
|
|
* |
|
388
|
|
|
* @since 3.1.4 |
|
389
|
|
|
* @param mixed $keys A string, or an array of strings, that contain keys. |
|
390
|
|
|
* @return mixed Returns TRUE if the key exists, otherwise FALSE Or if an array was passed to keys, then an |
|
391
|
|
|
* array is returned that contains all existing keys, or an empty array if none exist. |
|
392
|
|
|
*/ |
|
393
|
1 |
|
public function apc_exists($keys) |
|
394
|
|
|
{ |
|
395
|
1 |
|
$code = new Code(); |
|
396
|
1 |
|
$code->addStatement(sprintf( |
|
397
|
1 |
|
'return apc_exists(%s);', |
|
398
|
1 |
|
var_export($keys, true) |
|
399
|
1 |
|
)); |
|
400
|
|
|
|
|
401
|
1 |
|
return $this->adapter->run($code); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
/** |
|
405
|
|
|
* Fetch a stored variable from the cache |
|
406
|
|
|
* |
|
407
|
|
|
* @since 3.0.0 |
|
408
|
|
|
* @param mixed $key The key used to store the value (with apc_store()). If an array is passed then each element is fetched and returned. |
|
409
|
|
|
* @param \stdClass $ref success is set to TRUE in success and FALSE in failure |
|
410
|
|
|
* @return mixed The stored variable or array of variables on success; FALSE on failure |
|
411
|
|
|
*/ |
|
412
|
1 |
|
public function apc_fetch($key, $ref = false) |
|
413
|
|
|
{ |
|
414
|
1 |
|
$code = new Code(); |
|
415
|
1 |
|
$code->addStatement('$success = false;'); |
|
416
|
1 |
|
$code->addStatement(sprintf('$result = apc_fetch(%s, $success);', var_export($key, true))); |
|
417
|
1 |
|
$code->addStatement('return array($result, $success);'); |
|
418
|
|
|
|
|
419
|
1 |
|
list($var, $success) = $this->adapter->run($code); |
|
420
|
|
|
|
|
421
|
1 |
|
if (is_object($ref)) { |
|
422
|
1 |
|
$ref->success = $success; |
|
423
|
1 |
|
} |
|
424
|
|
|
|
|
425
|
1 |
|
return $var; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* Increase a stored number |
|
430
|
|
|
* |
|
431
|
|
|
* @since 3.1.1 |
|
432
|
|
|
* @param string $key The key of the value being increased. |
|
433
|
|
|
* @param int $step The step, or value to increased. |
|
434
|
|
|
* @param \stdClass $ref success is set to TRUE in success and FALSE in failure |
|
435
|
|
|
* @return mixed Returns the current value of key's value on success, or FALSE on failure |
|
436
|
|
|
*/ |
|
437
|
1 |
|
public function apc_inc($key, $step = 1, $ref = false) |
|
438
|
|
|
{ |
|
439
|
1 |
|
$code = new Code(); |
|
440
|
1 |
|
$code->addStatement('$success = false;'); |
|
441
|
1 |
|
$code->addStatement(sprintf( |
|
442
|
1 |
|
'$result = apc_inc(%s, %s, $success);', |
|
443
|
1 |
|
var_export($key, true), |
|
444
|
1 |
|
var_export($step, true) |
|
445
|
1 |
|
)); |
|
446
|
1 |
|
$code->addStatement('return array($result, $success);'); |
|
447
|
|
|
|
|
448
|
1 |
|
list($result, $success) = $this->adapter->run($code); |
|
449
|
|
|
|
|
450
|
1 |
|
if (is_object($ref)) { |
|
451
|
1 |
|
$ref->success = $success; |
|
452
|
1 |
|
} |
|
453
|
|
|
|
|
454
|
1 |
|
return $result; |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
/** |
|
458
|
|
|
* Loads a set of constants from the cache |
|
459
|
|
|
* |
|
460
|
|
|
* @since 3.0.0 |
|
461
|
|
|
* @param mixed $key The name of the constant set (that was stored with apc_define_constants()) to be |
|
462
|
|
|
* retrieved. |
|
463
|
|
|
* @param boolean $case_sensitive The default behaviour for constants is to be declared case-sensitive; i.e. |
|
464
|
|
|
* CONSTANT and Constant represent different values. If this parameter evaluates to |
|
465
|
|
|
* FALSE the constants will be declared as case-insensitive symbols. |
|
466
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
|
467
|
|
|
*/ |
|
468
|
1 |
|
public function apc_load_constants($key, $case_sensitive = true) |
|
469
|
|
|
{ |
|
470
|
1 |
|
$code = new Code(); |
|
471
|
1 |
|
$code->addStatement(sprintf( |
|
472
|
1 |
|
'return apc_load_constants(%s, %s);', |
|
473
|
1 |
|
var_export($key, true), |
|
474
|
1 |
|
var_export($case_sensitive, true) |
|
475
|
1 |
|
)); |
|
476
|
|
|
|
|
477
|
1 |
|
return $this->adapter->run($code); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* Retrieves APC's Shared Memory Allocation information |
|
482
|
|
|
* |
|
483
|
|
|
* @since 2.0.0 |
|
484
|
|
|
* @param boolean $limited When set to FALSE (default) apc_sma_info() will return a detailed information about |
|
485
|
|
|
* each segment. |
|
486
|
|
|
* @return boolean Array of Shared Memory Allocation data; FALSE on failure |
|
487
|
|
|
*/ |
|
488
|
1 |
|
public function apc_sma_info($limited = false) |
|
489
|
|
|
{ |
|
490
|
1 |
|
$code = new Code(); |
|
491
|
1 |
|
$code->addStatement(sprintf( |
|
492
|
1 |
|
'return apc_sma_info(%s);', |
|
493
|
1 |
|
var_export($limited, true) |
|
494
|
1 |
|
)); |
|
495
|
|
|
|
|
496
|
1 |
|
return $this->adapter->run($code); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* Cache a variable in the data store |
|
501
|
|
|
* |
|
502
|
|
|
* Note: Unlike many other mechanisms in PHP, variables stored using apc_store() will persist between requests |
|
503
|
|
|
* (until the value is removed from the cache). |
|
504
|
|
|
* |
|
505
|
|
|
* @since 3.0.0 |
|
506
|
|
|
* @param mixed $key Store the variable using this name. keys are cache-unique, so storing a second value with the |
|
507
|
|
|
* same key will overwrite the original value. |
|
508
|
|
|
* If $key is an array set Names in key, variables in value |
|
509
|
|
|
* @param mixed $var The variable to store |
|
510
|
|
|
* If $key is an array, this parameter is unused and set to NULL |
|
511
|
|
|
* @param int $ttl Time To Live; store var in the cache for ttl seconds. After the ttl has passed, the stored |
|
512
|
|
|
* variable will be expunged from the cache (on the next request). If no ttl is supplied (or if |
|
513
|
|
|
* the ttl is 0), the value will persist until it is removed from the cache manually, or |
|
514
|
|
|
* otherwise fails to exist in the cache (clear, restart, etc.). |
|
515
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. Second syntax returns array with error keys. |
|
516
|
|
|
*/ |
|
517
|
2 |
|
public function apc_store($key, $var = null, $ttl = 0) |
|
518
|
|
|
{ |
|
519
|
2 |
|
if (is_string($key) && $var === null) { |
|
520
|
1 |
|
throw new \InvalidArgumentException('When $key is set $var cannot be null'); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
1 |
|
$code = new Code(); |
|
524
|
1 |
|
$code->addStatement(sprintf( |
|
525
|
1 |
|
'return apc_store(%s, %s, %s);', |
|
526
|
1 |
|
var_export($key, true), |
|
527
|
1 |
|
var_export($var, true), |
|
528
|
1 |
|
var_export($ttl, true) |
|
529
|
1 |
|
)); |
|
530
|
|
|
|
|
531
|
1 |
|
return $this->adapter->run($code); |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* @return string |
|
536
|
|
|
*/ |
|
537
|
1 |
|
public function apc_version() |
|
538
|
|
|
{ |
|
539
|
1 |
|
$code = new Code(); |
|
540
|
1 |
|
$code->addStatement('return phpversion("apc");'); |
|
541
|
|
|
|
|
542
|
1 |
|
return $this->adapter->run($code); |
|
543
|
|
|
} |
|
544
|
|
|
} |
|
545
|
|
|
|