-
Notifications
You must be signed in to change notification settings - Fork 15
/
php_apc.c
280 lines (241 loc) · 7.67 KB
/
php_apc.c
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
+----------------------------------------------------------------------+
| APC |
+----------------------------------------------------------------------+
| Copyright (c) 2015-2019 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: krakjoe |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "php.h"
#include "zend.h"
#include "zend_API.h"
#include "zend_compile.h"
#include "zend_hash.h"
#include "zend_extensions.h"
#include "zend_interfaces.h"
#include "SAPI.h"
#include "php_apc.h"
#include "ext/standard/info.h"
#include "ext/apcu/php_apc.h"
#include "ext/apcu/apc_arginfo.h"
#include "ext/apcu/apc_iterator.h"
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
zend_class_entry *apc_bc_iterator_ce;
zend_object_handlers apc_bc_iterator_handlers;
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bc_cache_info, 0, 0, 0)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, limited)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bc_clear_cache, 0, 0, 0)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ PHP_FUNCTION declarations */
PHP_FUNCTION(apc_cache_info);
PHP_FUNCTION(apc_clear_cache);
/* }}} */
/* {{{ PHP_MINFO_FUNCTION(apc) */
static PHP_MINFO_FUNCTION(apc)
{
php_info_print_table_start();
php_info_print_table_row(2, "APC Compatibility", PHP_APCU_BC_VERSION);
php_info_print_table_end();
}
/* }}} */
static int apc_bc_iterator_init(int module_number);
/* {{{ PHP_RINIT_FUNCTION(apc) */
static PHP_RINIT_FUNCTION(apc)
{
#if defined(ZTS) && defined(COMPILE_DL_APC)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ proto void apc_clear_cache(string cache) */
PHP_FUNCTION(apc_clear_cache) {
zend_string *name = NULL;
zval proxy;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &name) != SUCCESS) {
return;
}
if (name && !strcasecmp(ZSTR_VAL(name), "user")) {
ZVAL_STR(&proxy,
zend_string_init(ZEND_STRL("apcu_clear_cache"), 0));
call_user_function(EG(function_table), NULL, &proxy, return_value, 0, NULL);
zval_ptr_dtor(&proxy);
}
}
/* }}} */
/* {{{ proto array apc_cache_info(string cache [, bool limited = false]) */
PHP_FUNCTION(apc_cache_info) {
zend_string *name = NULL;
zval param, *limited = ¶m, proxy;
ZVAL_FALSE(¶m);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|Sz", &name, &limited) != SUCCESS) {
return;
}
if (name && !strcasecmp(ZSTR_VAL(name), "user")) {
ZVAL_STR(&proxy,
zend_string_init(ZEND_STRL("apcu_cache_info"), 0));
call_user_function(EG(function_table), NULL, &proxy, return_value, 1, limited);
zval_ptr_dtor(&proxy);
}
}
/* }}} */
static void php_apcu_bc_inc_dec(INTERNAL_FUNCTION_PARAMETERS, zend_string *funcname) /* {{{ */
{
zend_string *key;
zend_long step = 1;
zval proxy, params[3], *success = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lz", &key, &step, &success) == FAILURE) {
return;
}
/* Check if key exists to keep old APC behavior */
ZVAL_STR(&proxy, zend_string_init(ZEND_STRL("apcu_exists"), 0));
ZVAL_STR(¶ms[0], key);
call_user_function(EG(function_table), NULL, &proxy, return_value, 1, params);
if (Z_TYPE_INFO_P(return_value) != IS_TRUE) {
if (success) {
ZVAL_DEREF(success);
zval_ptr_dtor(success);
ZVAL_FALSE(success);
}
RETURN_FALSE;
}
/* inc/dec the key */
ZVAL_STR(&proxy, funcname);
ZVAL_STR(¶ms[0], key);
ZVAL_LONG(¶ms[1], step);
if (success) {
ZVAL_COPY_VALUE(¶ms[2], success);
}
call_user_function(EG(function_table), NULL, &proxy, return_value, (success ? 3 : 2), params);
}
/* }}} */
/* {{{ proto long apc_inc(string key [, long step [, bool& success]])
*/
PHP_FUNCTION(apc_inc) {
php_apcu_bc_inc_dec(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_string_init(ZEND_STRL("apcu_inc"), 0));
}
/* }}} */
/* {{{ proto long apc_dec(string key [, long step [, bool &success]])
*/
PHP_FUNCTION(apc_dec) {
php_apcu_bc_inc_dec(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_string_init(ZEND_STRL("apcu_dec"), 0));
}
/* }}} */
/* {{{ apc_functions[] */
zend_function_entry apc_functions[] = {
PHP_FE(apc_cache_info, arginfo_apcu_bc_cache_info)
PHP_FE(apc_clear_cache, arginfo_apcu_bc_clear_cache)
PHP_FALIAS(apc_store, apcu_store, arginfo_apcu_store)
PHP_FALIAS(apc_fetch, apcu_fetch, arginfo_apcu_fetch)
PHP_FALIAS(apc_enabled, apcu_enabled, arginfo_apcu_enabled)
PHP_FALIAS(apc_delete, apcu_delete, arginfo_apcu_delete)
PHP_FALIAS(apc_add, apcu_add, arginfo_apcu_store)
PHP_FALIAS(apc_sma_info, apcu_sma_info, arginfo_apcu_sma_info)
PHP_FE(apc_inc, arginfo_apcu_inc)
PHP_FE(apc_dec, arginfo_apcu_inc)
PHP_FALIAS(apc_cas, apcu_cas, arginfo_apcu_cas)
PHP_FALIAS(apc_exists, apcu_exists, arginfo_apcu_exists)
PHP_FE_END
};
/* }}} */
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_apc_iterator___construct, 0, 0, 1)
ZEND_ARG_INFO(0, ignored)
ZEND_ARG_INFO(0, search)
ZEND_ARG_INFO(0, format)
ZEND_ARG_INFO(0, chunk_size)
ZEND_ARG_INFO(0, list)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ proto object APCIterator::__construct(cache, [ mixed search [, long format [, long chunk_size [, long list ]]]]) */
PHP_METHOD(apc_bc_iterator, __construct) {
apc_iterator_t *iterator = apc_iterator_fetch(getThis());
zend_long format = APC_ITER_ALL;
zend_long chunk_size=0;
zval *search = NULL;
zend_long list = APC_LIST_ACTIVE;
zend_string *cache;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|zlll", &cache, &search, &format, &chunk_size, &list) == FAILURE) {
return;
}
if (apc_is_enabled()) {
apc_iterator_obj_init(iterator, search, format, chunk_size, list);
}
}
/* }}} */
/* {{{ apc_iterator_functions */
static zend_function_entry apc_iterator_functions[] = {
PHP_ME(apc_bc_iterator, __construct, arginfo_apc_iterator___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_FE_END
};
/* }}} */
/* {{{ apc_bc_iterator_init */
static int apc_bc_iterator_init(int module_number) {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "APCIterator", apc_iterator_functions);
apc_bc_iterator_ce = zend_register_internal_class_ex(&ce, apc_iterator_get_ce());
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION(apc) */
static PHP_MINIT_FUNCTION(apc)
{
if (apc_iterator_get_ce()) {
apc_bc_iterator_init(module_number);
}
return SUCCESS;
}
static const zend_module_dep apc_deps[] = {
ZEND_MOD_REQUIRED("apcu")
ZEND_MOD_END
};
/* {{{ module definition structure */
zend_module_entry apc_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
apc_deps,
PHP_APC_EXTNAME,
apc_functions,
PHP_MINIT(apc),
NULL,
PHP_RINIT(apc),
NULL,
PHP_MINFO(apc),
PHP_APCU_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_APC
ZEND_GET_MODULE(apc)
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
#endif
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim>600: expandtab sw=4 ts=4 sts=4 fdm=marker
* vim<600: expandtab sw=4 ts=4 sts=4
*/