~ubuntu-branches/ubuntu/vivid/php-apcu/vivid

« back to all changes in this revision

Viewing changes to apcu-4.0.4/php_apc.c

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2014-06-24 10:52:52 UTC
  • mfrom: (7.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140624105252-vsqs1r4og4ykucqg
Tags: 4.0.6-1
* New upstream version 4.0.6
* Remove PHP 5.6 support patch - merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  +----------------------------------------------------------------------+
3
 
  | APC                                                                  |
4
 
  +----------------------------------------------------------------------+
5
 
  | Copyright (c) 2006-2011 The PHP Group                                |
6
 
  +----------------------------------------------------------------------+
7
 
  | This source file is subject to version 3.01 of the PHP license,      |
8
 
  | that is bundled with this package in the file LICENSE, and is        |
9
 
  | available through the world-wide-web at the following url:           |
10
 
  | http://www.php.net/license/3_01.txt                                  |
11
 
  | If you did not receive a copy of the PHP license and are unable to   |
12
 
  | obtain it through the world-wide-web, please send a note to          |
13
 
  | license@php.net so we can mail you a copy immediately.               |
14
 
  +----------------------------------------------------------------------+
15
 
  | Authors: Daniel Cowgill <dcowgill@communityconnect.com>              |
16
 
  |          Rasmus Lerdorf <rasmus@php.net>                             |
17
 
  +----------------------------------------------------------------------+
18
 
 
19
 
   This software was contributed to PHP by Community Connect Inc. in 2002
20
 
   and revised in 2005 by Yahoo! Inc. to add support for PHP 5.1.
21
 
   Future revisions and derivatives of this source code must acknowledge
22
 
   Community Connect Inc. as the original contributor of this module by
23
 
   leaving this note intact in the source code.
24
 
 
25
 
   All other licensing and usage conditions are those of the PHP Group.
26
 
 
27
 
 */
28
 
 
29
 
/* $Id: php_apc.c 328290 2012-11-09 03:30:09Z laruence $ */
30
 
 
31
 
#ifdef HAVE_CONFIG_H
32
 
# include "config.h"
33
 
#endif
34
 
 
35
 
#include "apc_cache.h"
36
 
#include "apc_iterator.h"
37
 
#include "apc_sma.h"
38
 
#include "apc_lock.h"
39
 
#include "apc_bin.h"
40
 
#include "php_globals.h"
41
 
#include "php_ini.h"
42
 
#include "ext/standard/info.h"
43
 
#include "ext/standard/file.h"
44
 
#include "ext/standard/flock_compat.h"
45
 
#include "ext/standard/md5.h"
46
 
#include "ext/standard/php_var.h"
47
 
 
48
 
#ifdef HAVE_SYS_FILE_H
49
 
#include <sys/file.h>
50
 
#endif
51
 
 
52
 
#include "SAPI.h"
53
 
#include "rfc1867.h"
54
 
#include "php_apc.h"
55
 
 
56
 
#if HAVE_SIGACTION
57
 
#include "apc_signal.h"
58
 
#endif
59
 
 
60
 
/* {{{ PHP_FUNCTION declarations */
61
 
PHP_FUNCTION(apcu_cache_info);
62
 
PHP_FUNCTION(apcu_clear_cache);
63
 
PHP_FUNCTION(apcu_sma_info);
64
 
PHP_FUNCTION(apcu_key_info);
65
 
PHP_FUNCTION(apcu_store);
66
 
PHP_FUNCTION(apcu_fetch);
67
 
PHP_FUNCTION(apcu_delete);
68
 
PHP_FUNCTION(apcu_add);
69
 
PHP_FUNCTION(apcu_inc);
70
 
PHP_FUNCTION(apcu_dec);
71
 
PHP_FUNCTION(apcu_cas);
72
 
PHP_FUNCTION(apcu_exists);
73
 
 
74
 
PHP_FUNCTION(apcu_bin_dump);
75
 
PHP_FUNCTION(apcu_bin_load);
76
 
PHP_FUNCTION(apcu_bin_dumpfile);
77
 
PHP_FUNCTION(apcu_bin_loadfile);
78
 
 
79
 
#ifdef APC_FULL_BC
80
 
PHP_FUNCTION(apc_bin_dumpfile);
81
 
PHP_FUNCTION(apc_bin_dump);
82
 
#endif
83
 
/* }}} */
84
 
 
85
 
/* {{{ ZEND_DECLARE_MODULE_GLOBALS(apcu) */
86
 
ZEND_DECLARE_MODULE_GLOBALS(apcu)
87
 
 
88
 
/* True globals */
89
 
apc_cache_t* apc_user_cache = NULL;
90
 
 
91
 
/* External APC SMA */
92
 
apc_sma_api_extern(apc_sma);
93
 
 
94
 
/* Global init functions */
95
 
static void php_apc_init_globals(zend_apcu_globals* apcu_globals TSRMLS_DC)
96
 
{
97
 
    apcu_globals->initialized = 0;
98
 
    apcu_globals->slam_defense = 1;
99
 
        apcu_globals->smart = 0;
100
 
 
101
 
#ifdef MULTIPART_EVENT_FORMDATA
102
 
    apcu_globals->rfc1867 = 0;
103
 
    memset(&(apcu_globals->rfc1867_data), 0, sizeof(apc_rfc1867_data));
104
 
#endif
105
 
        
106
 
        apcu_globals->preload_path = NULL;
107
 
    apcu_globals->coredump_unmap = 0;
108
 
    apcu_globals->use_request_time = 1;
109
 
    apcu_globals->serializer_name = NULL;
110
 
}
111
 
/* }}} */
112
 
 
113
 
/* {{{ PHP_INI */
114
 
 
115
 
static PHP_INI_MH(OnUpdateShmSegments) /* {{{ */
116
 
{
117
 
#if APC_MMAP
118
 
    if (zend_atoi(new_value, new_value_length)!=1) {
119
 
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "apc.shm_segments setting ignored in MMAP mode");
120
 
    }
121
 
    APCG(shm_segments) = 1;
122
 
#else
123
 
    APCG(shm_segments) = zend_atoi(new_value, new_value_length);
124
 
#endif
125
 
    return SUCCESS;
126
 
}
127
 
/* }}} */
128
 
 
129
 
static PHP_INI_MH(OnUpdateShmSize) /* {{{ */
130
 
{
131
 
    long s = zend_atol(new_value, new_value_length);
132
 
 
133
 
    if (s <= 0) {
134
 
        return FAILURE;
135
 
    }
136
 
 
137
 
    if (s < 1048576L) {
138
 
        /* if it's less than 1Mb, they are probably using the old syntax */
139
 
        php_error_docref(       
140
 
                        NULL TSRMLS_CC, E_WARNING, "apc.shm_size now uses M/G suffixes, please update your ini files");
141
 
        s = s * 1048576L;
142
 
    }
143
 
 
144
 
    APCG(shm_size) = s;
145
 
 
146
 
    return SUCCESS;
147
 
}
148
 
/* }}} */
149
 
 
150
 
#ifdef MULTIPART_EVENT_FORMDATA
151
 
static PHP_INI_MH(OnUpdateRfc1867Freq) /* {{{ */
152
 
{
153
 
    int tmp;
154
 
    tmp = zend_atoi(new_value, new_value_length);
155
 
    if (tmp < 0) {
156
 
        apc_error("rfc1867_freq must be greater than or equal to zero." TSRMLS_CC);
157
 
        return FAILURE;
158
 
    }
159
 
    if (new_value[new_value_length-1] == '%') {
160
 
        if (tmp > 100) {
161
 
            apc_error("rfc1867_freq cannot be over 100%%" TSRMLS_CC);
162
 
            return FAILURE;
163
 
        }
164
 
        APCG(rfc1867_freq) = tmp / 100.0;
165
 
    } else {
166
 
        APCG(rfc1867_freq) = tmp;
167
 
    }
168
 
    return SUCCESS;
169
 
}
170
 
/* }}} */
171
 
#endif
172
 
 
173
 
PHP_INI_BEGIN()
174
 
STD_PHP_INI_BOOLEAN("apc.enabled",      "1",    PHP_INI_SYSTEM, OnUpdateBool,              enabled,          zend_apcu_globals, apcu_globals)
175
 
STD_PHP_INI_ENTRY("apc.shm_segments",   "1",    PHP_INI_SYSTEM, OnUpdateShmSegments,       shm_segments,     zend_apcu_globals, apcu_globals)
176
 
STD_PHP_INI_ENTRY("apc.shm_size",       "32M",  PHP_INI_SYSTEM, OnUpdateShmSize,           shm_size,         zend_apcu_globals, apcu_globals)
177
 
STD_PHP_INI_ENTRY("apc.entries_hint",   "4096", PHP_INI_SYSTEM, OnUpdateLong,              entries_hint,     zend_apcu_globals, apcu_globals)
178
 
STD_PHP_INI_ENTRY("apc.gc_ttl",         "3600", PHP_INI_SYSTEM, OnUpdateLong,              gc_ttl,           zend_apcu_globals, apcu_globals)
179
 
STD_PHP_INI_ENTRY("apc.ttl",            "0",    PHP_INI_SYSTEM, OnUpdateLong,              ttl,              zend_apcu_globals, apcu_globals)
180
 
STD_PHP_INI_ENTRY("apc.smart",          "0",    PHP_INI_SYSTEM, OnUpdateLong,              smart,            zend_apcu_globals, apcu_globals)
181
 
#if APC_MMAP
182
 
STD_PHP_INI_ENTRY("apc.mmap_file_mask",  NULL,  PHP_INI_SYSTEM, OnUpdateString,            mmap_file_mask,   zend_apcu_globals, apcu_globals)
183
 
#endif
184
 
STD_PHP_INI_BOOLEAN("apc.enable_cli",   "0",    PHP_INI_SYSTEM, OnUpdateBool,              enable_cli,       zend_apcu_globals, apcu_globals)
185
 
STD_PHP_INI_BOOLEAN("apc.slam_defense", "1",    PHP_INI_SYSTEM, OnUpdateBool,              slam_defense,     zend_apcu_globals, apcu_globals)
186
 
#ifdef MULTIPART_EVENT_FORMDATA
187
 
STD_PHP_INI_BOOLEAN("apc.rfc1867", "0", PHP_INI_SYSTEM, OnUpdateBool, rfc1867, zend_apcu_globals, apcu_globals)
188
 
STD_PHP_INI_ENTRY("apc.rfc1867_prefix", "upload_", PHP_INI_SYSTEM, OnUpdateStringUnempty, rfc1867_prefix, zend_apcu_globals, apcu_globals)
189
 
STD_PHP_INI_ENTRY("apc.rfc1867_name", "APC_UPLOAD_PROGRESS", PHP_INI_SYSTEM, OnUpdateStringUnempty, rfc1867_name, zend_apcu_globals, apcu_globals)
190
 
STD_PHP_INI_ENTRY("apc.rfc1867_freq", "0", PHP_INI_SYSTEM, OnUpdateRfc1867Freq, rfc1867_freq, zend_apcu_globals, apcu_globals)
191
 
STD_PHP_INI_ENTRY("apc.rfc1867_ttl", "3600", PHP_INI_SYSTEM, OnUpdateLong, rfc1867_ttl, zend_apcu_globals, apcu_globals)
192
 
#endif
193
 
STD_PHP_INI_ENTRY("apc.preload_path", (char*)NULL,              PHP_INI_SYSTEM, OnUpdateString,       preload_path,  zend_apcu_globals, apcu_globals)
194
 
STD_PHP_INI_BOOLEAN("apc.coredump_unmap", "0", PHP_INI_SYSTEM, OnUpdateBool, coredump_unmap, zend_apcu_globals, apcu_globals)
195
 
STD_PHP_INI_BOOLEAN("apc.use_request_time", "1", PHP_INI_ALL, OnUpdateBool, use_request_time,  zend_apcu_globals, apcu_globals)
196
 
STD_PHP_INI_ENTRY("apc.serializer", "php", PHP_INI_SYSTEM, OnUpdateStringUnempty, serializer_name, zend_apcu_globals, apcu_globals)
197
 
STD_PHP_INI_ENTRY("apc.writable", "/tmp", PHP_INI_SYSTEM, OnUpdateStringUnempty, writable, zend_apcu_globals, apcu_globals)
198
 
PHP_INI_END()
199
 
 
200
 
/* }}} */
201
 
 
202
 
/* {{{ PHP_MINFO_FUNCTION(apcu) */
203
 
static PHP_MINFO_FUNCTION(apcu)
204
 
{
205
 
    php_info_print_table_start();
206
 
    php_info_print_table_header(2, "APCu Support", APCG(enabled) ? "Enabled" : "Disabled");
207
 
    php_info_print_table_row(2, "Version", PHP_APCU_VERSION);
208
 
#ifdef APC_DEBUG
209
 
    php_info_print_table_row(2, "APCu Debugging", "Enabled");
210
 
#else
211
 
    php_info_print_table_row(2, "APCu Debugging", "Disabled");
212
 
#endif
213
 
#if APC_MMAP
214
 
    php_info_print_table_row(2, "MMAP Support", "Enabled");
215
 
    php_info_print_table_row(2, "MMAP File Mask", APCG(mmap_file_mask));
216
 
#else
217
 
    php_info_print_table_row(2, "MMAP Support", "Disabled");
218
 
#endif
219
 
 
220
 
    if (APCG(enabled)) {
221
 
        apc_serializer_t *serializer = NULL;
222
 
        smart_str names = {0,};
223
 
        int i;
224
 
    
225
 
        for( i = 0, serializer = apc_get_serializers(TSRMLS_C); 
226
 
                    serializer->name != NULL; 
227
 
                    serializer++, i++) {
228
 
            if (i != 0) {
229
 
                            smart_str_appends(&names, ", ");
230
 
                    }
231
 
            smart_str_appends(&names, serializer->name);
232
 
        }
233
 
    
234
 
        if (names.c) {
235
 
            smart_str_0(&names);
236
 
            php_info_print_table_row(2, "Serialization Support", names.c);
237
 
            smart_str_free(&names);
238
 
        } else {
239
 
            php_info_print_table_row(2, "Serialization Support", "Broken");
240
 
        }
241
 
    } else {
242
 
        php_info_print_table_row(2, "Serialization Support", "Disabled");
243
 
    }
244
 
 
245
 
    php_info_print_table_row(2, "Revision", "$Revision: 328290 $");
246
 
    php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
247
 
    php_info_print_table_end();
248
 
    DISPLAY_INI_ENTRIES();
249
 
}
250
 
/* }}} */
251
 
 
252
 
#ifdef MULTIPART_EVENT_FORMDATA
253
 
extern int apc_rfc1867_progress(unsigned int event, void *event_data, void **extra TSRMLS_DC);
254
 
#endif
255
 
 
256
 
#ifdef APC_FULL_BC
257
 
static void apc_init(INIT_FUNC_ARGS);
258
 
#endif
259
 
 
260
 
/* {{{ PHP_MINIT_FUNCTION(apcu) */
261
 
static PHP_MINIT_FUNCTION(apcu)
262
 
{
263
 
    ZEND_INIT_MODULE_GLOBALS(apcu, php_apc_init_globals, NULL);
264
 
 
265
 
    REGISTER_INI_ENTRIES();
266
 
 
267
 
        /* locks initialized regardless of settings */
268
 
        apc_lock_init(TSRMLS_C);
269
 
        
270
 
    /* Disable APC in cli mode unless overridden by apc.enable_cli */
271
 
    if (!APCG(enable_cli) && !strcmp(sapi_module.name, "cli")) {
272
 
        APCG(enabled) = 0;
273
 
    }
274
 
 
275
 
        /* only run initialization if APC is enabled */
276
 
    if (APCG(enabled)) {
277
 
 
278
 
        if (!APCG(initialized)) {
279
 
                        /* ensure this runs only once */
280
 
                        APCG(initialized) = 1;
281
 
                        
282
 
                        /* initialize shared memory allocator */
283
 
#if APC_MMAP
284
 
                        apc_sma.init(APCG(shm_segments), APCG(shm_size), APCG(mmap_file_mask) TSRMLS_CC);
285
 
#else
286
 
                        apc_sma.init(APCG(shm_segments), APCG(shm_size), NULL TSRMLS_CC);
287
 
#endif
288
 
 
289
 
/* XXX pack this into macros when there are more hooks to handle */
290
 
#if defined(PHP_WIN32) && defined(_WIN64)
291
 
                        do {
292
 
                                 char buf[65];
293
 
 
294
 
                                 if (!_i64toa_s((__int64)_apc_register_serializer, buf, 65, 10)) {
295
 
                                        REGISTER_STRING_CONSTANT(APC_SERIALIZER_CONSTANT, buf, CONST_PERSISTENT | CONST_CS);
296
 
                                 } else {
297
 
                                        /* subsequent apc_register_serializer() calls will be void */
298
 
                                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Serializer hook init failed");
299
 
                                 }
300
 
                        } while (0);
301
 
#else
302
 
                        REGISTER_LONG_CONSTANT(APC_SERIALIZER_CONSTANT, (long)&_apc_register_serializer, CONST_PERSISTENT | CONST_CS);
303
 
#endif
304
 
 
305
 
                        /* register default serializer */
306
 
                        _apc_register_serializer(
307
 
                                "php", APC_SERIALIZER_NAME(php), APC_UNSERIALIZER_NAME(php), NULL TSRMLS_CC);
308
 
 
309
 
                        /* test out the constant function pointer */
310
 
                        assert(apc_get_serializers(TSRMLS_C)->name != NULL);
311
 
 
312
 
                        /* create user cache */
313
 
                        apc_user_cache = apc_cache_create(
314
 
                                &apc_sma,
315
 
                                apc_find_serializer(APCG(serializer_name) TSRMLS_CC),
316
 
                                APCG(entries_hint), APCG(gc_ttl), APCG(ttl), APCG(smart), APCG(slam_defense)
317
 
                                TSRMLS_CC
318
 
                        );
319
 
                        
320
 
                        /* initialize pooling */
321
 
                        apc_pool_init();
322
 
                        
323
 
                        /* preload data from path specified in configuration */
324
 
                        if (APCG(preload_path)) {
325
 
                                apc_cache_preload(
326
 
                                        apc_user_cache, APCG(preload_path) TSRMLS_CC);
327
 
                        }
328
 
 
329
 
#ifdef MULTIPART_EVENT_FORMDATA
330
 
            /* File upload progress tracking */
331
 
            if (APCG(rfc1867)) {
332
 
                php_rfc1867_callback = apc_rfc1867_progress;
333
 
            }
334
 
#endif
335
 
 
336
 
                        /* initialize iterator object */
337
 
            apc_iterator_init(module_number TSRMLS_CC);
338
 
        }
339
 
 
340
 
        REGISTER_LONG_CONSTANT("APC_BIN_VERIFY_MD5", APC_BIN_VERIFY_MD5, CONST_CS | CONST_PERSISTENT);
341
 
        REGISTER_LONG_CONSTANT("APC_BIN_VERIFY_CRC32", APC_BIN_VERIFY_CRC32, CONST_CS | CONST_PERSISTENT);
342
 
    }
343
 
 
344
 
#ifndef REGISTER_BOOL_CONSTANT
345
 
    {
346
 
        zend_constant apc_bc;
347
 
        Z_TYPE(apc_bc.value) = IS_BOOL;
348
 
#if defined(APC_FULL_BC) && APC_FULL_BC
349
 
        Z_LVAL(apc_bc.value) = 1;
350
 
#else
351
 
        Z_LVAL(apc_bc.value) = 0;
352
 
#endif
353
 
        apc_bc.flags = (CONST_CS | CONST_PERSISTENT);
354
 
        apc_bc.name = zend_strndup(ZEND_STRL("APCU_APC_FULL_BC"));
355
 
        apc_bc.name_len = sizeof("APCU_APC_FULL_BC");
356
 
        apc_bc.module_number = module_number;
357
 
        zend_register_constant(&apc_bc TSRMLS_CC);
358
 
    }
359
 
#else
360
 
#if defined(APC_FULL_BC) && APC_FULL_BC
361
 
    REGISTER_BOOL_CONSTANT("APCU_APC_FULL_BC", 1, CONST_CS | CONST_PERSISTENT);
362
 
#else
363
 
    REGISTER_BOOL_CONSTANT("APCU_APC_FULL_BC", 0, CONST_CS | CONST_PERSISTENT);
364
 
#endif
365
 
#endif
366
 
 
367
 
#ifdef APC_FULL_BC
368
 
        apc_init(INIT_FUNC_ARGS_PASSTHRU);
369
 
#endif
370
 
 
371
 
    return SUCCESS;
372
 
}
373
 
/* }}} */
374
 
 
375
 
/* {{{ PHP_MSHUTDOWN_FUNCTION(apcu) */
376
 
static PHP_MSHUTDOWN_FUNCTION(apcu)
377
 
{
378
 
        /* locks shutdown regardless of settings */
379
 
        apc_lock_cleanup(TSRMLS_C);
380
 
 
381
 
        /* only shut down if APC is enabled */
382
 
    if (APCG(enabled)) {
383
 
        if (APCG(initialized)) {
384
 
 
385
 
                        /* destroy cache pointer */
386
 
                        apc_cache_destroy(apc_user_cache TSRMLS_CC);
387
 
                        /* cleanup shared memory */
388
 
                        apc_sma.cleanup(TSRMLS_C);
389
 
 
390
 
                        APCG(initialized) = 0;
391
 
                }
392
 
                
393
 
#if HAVE_SIGACTION
394
 
        apc_shutdown_signals(TSRMLS_C);
395
 
#endif
396
 
    }
397
 
 
398
 
#ifdef ZTS
399
 
    ts_free_id(apcu_globals_id);
400
 
#endif
401
 
 
402
 
    UNREGISTER_INI_ENTRIES();
403
 
    return SUCCESS;
404
 
} /* }}} */
405
 
 
406
 
/* {{{ PHP_RINIT_FUNCTION(apcu) */
407
 
static PHP_RINIT_FUNCTION(apcu)
408
 
{
409
 
    if (APCG(enabled)) {
410
 
        if (APCG(serializer_name)) {
411
 
                    /* Avoid race conditions between MINIT of apc and serializer exts like igbinary */
412
 
                        apc_cache_serializer(apc_user_cache, APCG(serializer_name) TSRMLS_CC);
413
 
                }
414
 
 
415
 
#if HAVE_SIGACTION
416
 
        apc_set_signals(TSRMLS_C);
417
 
#endif
418
 
    }
419
 
    return SUCCESS;
420
 
}
421
 
/* }}} */
422
 
 
423
 
#ifdef APC_FULL_BC
424
 
/* {{{ proto void apc_clear_cache([string cache]) */
425
 
PHP_FUNCTION(apcu_clear_cache)
426
 
{
427
 
    char *ignored;
428
 
    int ignlen = 0;
429
 
 
430
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ignored, &ignlen) == FAILURE) {
431
 
        return;
432
 
    }
433
 
 
434
 
    if (0 == ignlen || APC_CACHE_IS_USER(ignored, ignlen)) {
435
 
        apc_cache_clear(apc_user_cache TSRMLS_CC);
436
 
    }
437
 
 
438
 
    RETURN_TRUE;
439
 
}
440
 
/* }}} */
441
 
 
442
 
/* {{{ proto array apc_cache_info(string cache_type, [bool limited]) */
443
 
PHP_FUNCTION(apcu_cache_info)
444
 
{
445
 
    zval* info;
446
 
    zend_bool limited = 0;
447
 
    char *ct;
448
 
    ulong ctlen;
449
 
    
450
 
    if (ZEND_NUM_ARGS()) {
451
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &ct, &ctlen, &limited) == FAILURE) {
452
 
            return;
453
 
        }
454
 
    }
455
 
 
456
 
    info = apc_cache_info(apc_user_cache, limited TSRMLS_CC);
457
 
 
458
 
    if (!info) {
459
 
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No APC info available.  Perhaps APC is not enabled? Check apc.enabled in your ini file");
460
 
        RETURN_FALSE;
461
 
    }
462
 
 
463
 
    RETURN_ZVAL(info, 0, 1);
464
 
 
465
 
}
466
 
/* }}} */
467
 
#else
468
 
/* {{{ proto void apc_clear_cache() */
469
 
PHP_FUNCTION(apcu_clear_cache)
470
 
{
471
 
    if (zend_parse_parameters_none() == FAILURE) {
472
 
        return;
473
 
    }
474
 
 
475
 
    apc_cache_clear(
476
 
                apc_user_cache TSRMLS_CC);
477
 
    RETURN_TRUE;
478
 
}
479
 
/* }}} */
480
 
 
481
 
/* {{{ proto array apc_cache_info([bool limited]) */
482
 
PHP_FUNCTION(apcu_cache_info)
483
 
{
484
 
    zval* info;
485
 
    zend_bool limited = 0;
486
 
 
487
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &limited) == FAILURE) {
488
 
        return;
489
 
    }
490
 
 
491
 
    info = apc_cache_info(apc_user_cache, limited TSRMLS_CC);
492
 
 
493
 
    if (!info) {
494
 
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No APC info available.  Perhaps APC is not enabled? Check apc.enabled in your ini file");
495
 
        RETURN_FALSE;
496
 
    }
497
 
 
498
 
    RETURN_ZVAL(info, 0, 1);
499
 
 
500
 
}
501
 
/* }}} */
502
 
#endif
503
 
 
504
 
PHP_FUNCTION(apcu_key_info)
505
 
{
506
 
    zval *stat;
507
 
    char *strkey;
508
 
    zend_uint keylen;
509
 
    
510
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &strkey, &keylen) == FAILURE) {
511
 
        return;
512
 
    }
513
 
    
514
 
    stat = apc_cache_stat(
515
 
        apc_user_cache, strkey, keylen+1 TSRMLS_CC);
516
 
    
517
 
    RETURN_ZVAL(stat, 0, 1);
518
 
}
519
 
 
520
 
/* {{{ proto array apc_sma_info([bool limited]) */
521
 
PHP_FUNCTION(apcu_sma_info)
522
 
{
523
 
    apc_sma_info_t* info;
524
 
    zval* block_lists;
525
 
    int i;
526
 
    zend_bool limited = 0;
527
 
 
528
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &limited) == FAILURE) {
529
 
        return;
530
 
    }
531
 
 
532
 
    info = apc_sma.info(limited TSRMLS_CC);
533
 
 
534
 
    if (!info) {
535
 
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No APC SMA info available.  Perhaps APC is disabled via apc.enabled?");
536
 
        RETURN_FALSE;
537
 
    }
538
 
    array_init(return_value);
539
 
 
540
 
    add_assoc_long(return_value, "num_seg", info->num_seg);
541
 
    add_assoc_double(return_value, "seg_size", (double)info->seg_size);
542
 
    add_assoc_double(return_value, "avail_mem", (double)apc_sma.get_avail_mem());
543
 
 
544
 
    if (limited) {
545
 
        apc_sma.free_info(info TSRMLS_CC);
546
 
        return;
547
 
    }
548
 
 
549
 
    ALLOC_INIT_ZVAL(block_lists);
550
 
    array_init(block_lists);
551
 
 
552
 
    for (i = 0; i < info->num_seg; i++) {
553
 
        apc_sma_link_t* p;
554
 
        zval* list;
555
 
 
556
 
        ALLOC_INIT_ZVAL(list);
557
 
        array_init(list);
558
 
 
559
 
        for (p = info->list[i]; p != NULL; p = p->next) {
560
 
            zval* link;
561
 
 
562
 
            ALLOC_INIT_ZVAL(link);
563
 
            array_init(link);
564
 
 
565
 
            add_assoc_long(link, "size", p->size);
566
 
            add_assoc_long(link, "offset", p->offset);
567
 
            add_next_index_zval(list, link);
568
 
        }
569
 
        add_next_index_zval(block_lists, list);
570
 
    }
571
 
    add_assoc_zval(return_value, "block_lists", block_lists);
572
 
    apc_sma.free_info(info TSRMLS_CC);
573
 
}
574
 
/* }}} */
575
 
 
576
 
/* {{{ php_apc_update  */
577
 
int php_apc_update(char *strkey, int strkey_len, apc_cache_updater_t updater, void* data TSRMLS_DC) 
578
 
{
579
 
    if (!APCG(enabled)) {
580
 
        return 0;
581
 
    }
582
 
 
583
 
    if (APCG(serializer_name)) {
584
 
        /* Avoid race conditions between MINIT of apc and serializer exts like igbinary */
585
 
        apc_cache_serializer(apc_user_cache, APCG(serializer_name) TSRMLS_CC);
586
 
    }
587
 
 
588
 
    HANDLE_BLOCK_INTERRUPTIONS();
589
 
    
590
 
    if (!apc_cache_update(apc_user_cache, strkey, strkey_len + 1, updater, data TSRMLS_CC)) {
591
 
        HANDLE_UNBLOCK_INTERRUPTIONS();
592
 
        return 0;
593
 
    }
594
 
 
595
 
    HANDLE_UNBLOCK_INTERRUPTIONS();
596
 
 
597
 
    return 1;
598
 
}
599
 
/* }}} */
600
 
 
601
 
/* {{{ apc_store_helper(INTERNAL_FUNCTION_PARAMETERS, const zend_bool exclusive)
602
 
 */
603
 
static void apc_store_helper(INTERNAL_FUNCTION_PARAMETERS, const zend_bool exclusive)
604
 
{
605
 
    zval *key = NULL;
606
 
    zval *val = NULL;
607
 
    long ttl = 0L;
608
 
    
609
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zl", &key, &val, &ttl) == FAILURE) {
610
 
        return;
611
 
    }
612
 
 
613
 
    if (!key || !APCG(enabled)) {
614
 
        /* cannot work without key */
615
 
        RETURN_FALSE;
616
 
    }
617
 
 
618
 
    HANDLE_BLOCK_INTERRUPTIONS();
619
 
    
620
 
        /* keep it tidy */
621
 
    {
622
 
                if (APCG(serializer_name)) {
623
 
                /* Avoid race conditions between MINIT of apc and serializer exts like igbinary */
624
 
                    apc_cache_serializer(apc_user_cache, APCG(serializer_name) TSRMLS_CC);
625
 
                }
626
 
 
627
 
                if (Z_TYPE_P(key) == IS_ARRAY) {
628
 
            
629
 
            zval **hentry;
630
 
            char *hkey = NULL;
631
 
            zend_uint hkey_len;
632
 
            zend_ulong hkey_idx;
633
 
 
634
 
            HashPosition hpos;
635
 
            HashTable* hash = Z_ARRVAL_P(key);
636
 
 
637
 
            /* note: only indicative of error */
638
 
                    array_init(return_value);
639
 
                    zend_hash_internal_pointer_reset_ex(hash, &hpos);
640
 
                    while(zend_hash_get_current_data_ex(hash, (void**)&hentry, &hpos) == SUCCESS) {
641
 
                        zend_hash_get_current_key_ex(hash, &hkey, &hkey_len, &hkey_idx, 0, &hpos);
642
 
                        if (hkey) {
643
 
                            if(!apc_cache_store(apc_user_cache, hkey, hkey_len, *hentry, (zend_uint) ttl, exclusive TSRMLS_CC)) {
644
 
                                add_assoc_long_ex(return_value, hkey, hkey_len, -1);  /* -1: insertion error */
645
 
                            }
646
 
                    /* reset key for next element */
647
 
                            hkey = NULL;
648
 
                        } else {
649
 
                            add_index_long(return_value, hkey_idx, -1);  /* -1: insertion error */
650
 
                        }
651
 
                        zend_hash_move_forward_ex(hash, &hpos);
652
 
                    }
653
 
                        return;
654
 
                } else {
655
 
            if (Z_TYPE_P(key) == IS_STRING) {
656
 
                            if (!val) {
657
 
                    /* nothing to store */
658
 
                    HANDLE_UNBLOCK_INTERRUPTIONS();
659
 
                    RETURN_FALSE;
660
 
                }
661
 
                /* return true on success */
662
 
                        if(apc_cache_store(apc_user_cache, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, val, (zend_uint) ttl, exclusive TSRMLS_CC)) {
663
 
                                HANDLE_UNBLOCK_INTERRUPTIONS();
664
 
                    RETURN_TRUE;
665
 
                }
666
 
                } else {
667
 
                apc_warning("apc_store expects key parameter to be a string or an array of key/value pairs." TSRMLS_CC);
668
 
                }
669
 
        }
670
 
        }
671
 
        
672
 
        HANDLE_UNBLOCK_INTERRUPTIONS();
673
 
        
674
 
        /* default */
675
 
    RETURN_FALSE;
676
 
}
677
 
/* }}} */
678
 
 
679
 
/* {{{ proto bool apcu_enabled(void)
680
 
    returns true when apcu is usable in the current environment */
681
 
PHP_FUNCTION(apcu_enabled) {
682
 
    RETURN_BOOL(APCG(enabled));
683
 
}  /* }}} */
684
 
 
685
 
/* {{{ proto int apc_store(mixed key, mixed var [, long ttl ])
686
 
 */
687
 
PHP_FUNCTION(apcu_store) {
688
 
    apc_store_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
689
 
}
690
 
/* }}} */
691
 
 
692
 
/* {{{ proto int apc_add(mixed key, mixed var [, long ttl ])
693
 
 */
694
 
PHP_FUNCTION(apcu_add) {
695
 
    apc_store_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
696
 
}
697
 
/* }}} */
698
 
 
699
 
/* {{{ php_inc_updater */
700
 
 
701
 
struct php_inc_updater_args {
702
 
    long step;
703
 
    long lval;
704
 
};
705
 
 
706
 
static zend_bool php_inc_updater(apc_cache_t* cache, apc_cache_entry_t* entry, void* data) {
707
 
 
708
 
    struct php_inc_updater_args *args = (struct php_inc_updater_args*) data;
709
 
    
710
 
    zval* val = entry->val;
711
 
 
712
 
    if (Z_TYPE_P(val) == IS_LONG) {
713
 
        Z_LVAL_P(val) += args->step;
714
 
        args->lval = Z_LVAL_P(val);
715
 
        return 1;
716
 
    }
717
 
 
718
 
    return 0;
719
 
}
720
 
/* }}} */
721
 
 
722
 
/* {{{ proto long apc_inc(string key [, long step [, bool& success]])
723
 
 */
724
 
PHP_FUNCTION(apcu_inc) {
725
 
    char *strkey;
726
 
    int strkey_len;
727
 
    struct php_inc_updater_args args = {1L, -1};
728
 
    zval *success = NULL;
729
 
 
730
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz", &strkey, &strkey_len, &(args.step), &success) == FAILURE) {
731
 
        return;
732
 
    }
733
 
    
734
 
        if (success) {
735
 
                zval_dtor(success);
736
 
        }
737
 
 
738
 
    if (php_apc_update(strkey, strkey_len, php_inc_updater, &args TSRMLS_CC)) {
739
 
        if (success) {
740
 
                        ZVAL_TRUE(success);
741
 
                }
742
 
 
743
 
        RETURN_LONG(args.lval);
744
 
    }
745
 
    
746
 
    if (success) {
747
 
                ZVAL_FALSE(success);
748
 
        }
749
 
    
750
 
    RETURN_FALSE;
751
 
}
752
 
/* }}} */
753
 
 
754
 
/* {{{ proto long apc_dec(string key [, long step [, bool &success]])
755
 
 */
756
 
PHP_FUNCTION(apcu_dec) {
757
 
    char *strkey;
758
 
    int strkey_len;
759
 
    struct php_inc_updater_args args = {1L, -1};
760
 
    zval *success = NULL;
761
 
 
762
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz", &strkey, &strkey_len, &(args.step), &success) == FAILURE) {
763
 
        return;
764
 
    }
765
 
    
766
 
        if (success) {
767
 
                zval_dtor(success);
768
 
        }
769
 
 
770
 
    args.step = args.step * -1;
771
 
 
772
 
    if (php_apc_update(strkey, strkey_len, php_inc_updater, &args TSRMLS_CC)) {
773
 
        if (success) ZVAL_TRUE(success);
774
 
        RETURN_LONG(args.lval);
775
 
    }
776
 
    
777
 
    if (success) {
778
 
                ZVAL_FALSE(success);
779
 
        }
780
 
    
781
 
    RETURN_FALSE;
782
 
}
783
 
/* }}} */
784
 
 
785
 
/* {{{ php_cas_updater */
786
 
static zend_bool php_cas_updater(apc_cache_t* cache, apc_cache_entry_t* entry, void* data) {
787
 
    long* vals = ((long*)data);
788
 
    long old = vals[0];
789
 
    long new = vals[1];
790
 
    zval* val = entry->val;
791
 
 
792
 
    if (Z_TYPE_P(val) == IS_LONG) {
793
 
        if (Z_LVAL_P(val) == old) {
794
 
            Z_LVAL_P(val) = new;
795
 
            return 1;
796
 
        }
797
 
    }
798
 
 
799
 
    return 0;
800
 
}
801
 
/* }}} */
802
 
 
803
 
/* {{{ proto int apc_cas(string key, int old, int new)
804
 
 */
805
 
PHP_FUNCTION(apcu_cas) {
806
 
    char *strkey;
807
 
    int strkey_len;
808
 
    long vals[2];
809
 
 
810
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &strkey, &strkey_len, &vals[0], &vals[1]) == FAILURE) {
811
 
        return;
812
 
    }
813
 
 
814
 
    if (php_apc_update(strkey, strkey_len, php_cas_updater, &vals TSRMLS_CC)) {
815
 
                RETURN_TRUE;
816
 
        }
817
 
 
818
 
    RETURN_FALSE;
819
 
}
820
 
/* }}} */
821
 
 
822
 
void *apc_erealloc_wrapper(void *ptr, size_t size) {
823
 
    return _erealloc(ptr, size, 0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
824
 
}
825
 
 
826
 
/* {{{ proto mixed apc_fetch(mixed key[, bool &success])
827
 
 */
828
 
PHP_FUNCTION(apcu_fetch) {
829
 
    zval *key;
830
 
    zval *success = NULL;
831
 
    apc_cache_entry_t* entry;
832
 
    time_t t;
833
 
    apc_context_t ctxt = {0,};
834
 
 
835
 
    if (!APCG(enabled)) {
836
 
                RETURN_FALSE;
837
 
        }
838
 
 
839
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &key, &success) == FAILURE) {
840
 
        return;
841
 
    }
842
 
 
843
 
    t = apc_time();
844
 
 
845
 
    if (success) {
846
 
        ZVAL_BOOL(success, 0);
847
 
    }
848
 
 
849
 
        if (Z_TYPE_P(key) != IS_STRING && Z_TYPE_P(key) != IS_ARRAY) {
850
 
            convert_to_string(key);
851
 
        }
852
 
        
853
 
        /* check for a string, or array of strings */
854
 
        if (Z_TYPE_P(key) == IS_ARRAY || (Z_TYPE_P(key) == IS_STRING && Z_STRLEN_P(key) > 0)) {
855
 
                
856
 
                /* initialize a context */
857
 
                if (apc_cache_make_context(apc_user_cache, &ctxt, APC_CONTEXT_NOSHARE, APC_UNPOOL, APC_COPY_OUT, 0 TSRMLS_CC)) {
858
 
                        
859
 
                        if (Z_TYPE_P(key) == IS_STRING) {
860
 
 
861
 
                                /* do find using string as key */
862
 
                                if ((entry = apc_cache_find(apc_user_cache, Z_STRVAL_P(key), (Z_STRLEN_P(key) + 1), t TSRMLS_CC))) {
863
 
                                    /* deep-copy returned shm zval to emalloc'ed return_value */
864
 
                                    apc_cache_fetch_zval(
865
 
                                                &ctxt, return_value, entry->val TSRMLS_CC);
866
 
                                        /* decrement refcount of entry */
867
 
                                    apc_cache_release(
868
 
                                                apc_user_cache, entry TSRMLS_CC);
869
 
                                        /* set success */
870
 
                                        if (success) {
871
 
                                                ZVAL_BOOL(success, 1);
872
 
                                        }
873
 
 
874
 
                                } else { ZVAL_BOOL(return_value, 0); }
875
 
 
876
 
                        } else if (Z_TYPE_P(key) == IS_ARRAY) {
877
 
 
878
 
                                /* do find using key as array of strings */
879
 
                                HashPosition hpos;
880
 
                                zval **hentry;
881
 
                                zval *result;
882
 
                
883
 
                                MAKE_STD_ZVAL(result);
884
 
                                array_init(result);
885
 
                                
886
 
                                zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(key), &hpos);
887
 
                                while(zend_hash_get_current_data_ex(Z_ARRVAL_P(key), (void**)&hentry, &hpos) == SUCCESS) {
888
 
 
889
 
                                    if (Z_TYPE_PP(hentry) == IS_STRING) {
890
 
 
891
 
                                        /* perform find using this index as key */
892
 
                                                if ((entry = apc_cache_find(apc_user_cache, Z_STRVAL_PP(hentry), (Z_STRLEN_PP(hentry) + 1), t TSRMLS_CC))) {
893
 
                                                        zval *result_entry;
894
 
 
895
 
                                                    /* deep-copy returned shm zval to emalloc'ed return_value */
896
 
                                                    MAKE_STD_ZVAL(result_entry);
897
 
                                                    apc_cache_fetch_zval(
898
 
                                                                &ctxt, result_entry, entry->val TSRMLS_CC);
899
 
                                                        /* decrement refcount of entry */
900
 
                                                    apc_cache_release(
901
 
                                                                apc_user_cache, entry TSRMLS_CC);
902
 
                                                        /* add the emalloced value to return array */
903
 
                                                    zend_hash_add(
904
 
                                                                Z_ARRVAL_P(result), Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) +1, &result_entry, sizeof(zval*), NULL);
905
 
                                                }
906
 
                                    } else {
907
 
 
908
 
                                                /* we do not break loop, we just skip the key */
909
 
                                                apc_warning(
910
 
                                                        "apc_fetch() expects a string or array of strings." TSRMLS_CC);
911
 
                                        }
912
 
 
913
 
                                        /* don't set values we didn't find */
914
 
                                    zend_hash_move_forward_ex(Z_ARRVAL_P(key), &hpos);
915
 
                                }
916
 
 
917
 
                                RETVAL_ZVAL(result, 0, 1);
918
 
 
919
 
                                if (success) {
920
 
                                        ZVAL_BOOL(success, 1);
921
 
                                }
922
 
                        }
923
 
 
924
 
                        apc_cache_destroy_context(&ctxt TSRMLS_CC );    
925
 
                }
926
 
 
927
 
        } else { 
928
 
                apc_warning("apc_fetch() expects a string or array of strings." TSRMLS_CC);
929
 
                RETURN_FALSE; 
930
 
        }
931
 
    return;
932
 
}
933
 
/* }}} */
934
 
 
935
 
/* {{{ proto mixed apc_exists(mixed key)
936
 
 */
937
 
PHP_FUNCTION(apcu_exists) {
938
 
    zval *key;
939
 
    time_t t;
940
 
 
941
 
    if (!APCG(enabled)) {
942
 
                RETURN_FALSE;
943
 
        }
944
 
 
945
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &key) == FAILURE) {
946
 
        return;
947
 
    }
948
 
 
949
 
    t = apc_time();
950
 
 
951
 
    if (Z_TYPE_P(key) != IS_STRING && Z_TYPE_P(key) != IS_ARRAY) {
952
 
        convert_to_string(key);
953
 
    }
954
 
 
955
 
    if (Z_TYPE_P(key) == IS_STRING) {
956
 
        if (Z_STRLEN_P(key)) {
957
 
                    if (apc_cache_exists(apc_user_cache, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, t TSRMLS_CC)) {
958
 
                        RETURN_TRUE;
959
 
                    } else {
960
 
                                RETURN_FALSE;                   
961
 
                        }
962
 
                }
963
 
    } else if (Z_TYPE_P(key) == IS_ARRAY) {
964
 
        HashPosition hpos;
965
 
                zval **hentry;
966
 
                zval *result;
967
 
                
968
 
        MAKE_STD_ZVAL(result);
969
 
        array_init(result); 
970
 
 
971
 
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(key), &hpos);
972
 
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(key), (void**)&hentry, &hpos) == SUCCESS) {
973
 
            if (Z_TYPE_PP(hentry) == IS_STRING) {
974
 
               if (apc_cache_exists(apc_user_cache, Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) + 1, t TSRMLS_CC)) {
975
 
                                        zval *result_entry;
976
 
                                
977
 
                            MAKE_STD_ZVAL(result_entry);
978
 
                            ZVAL_BOOL(result_entry, 1);
979
 
                                
980
 
                            zend_hash_add(
981
 
                                                Z_ARRVAL_P(result), 
982
 
                                                Z_STRVAL_PP(hentry), Z_STRLEN_PP(hentry) +1, 
983
 
                                                &result_entry, sizeof(zval*), NULL
984
 
                                        );
985
 
                        }
986
 
            } else {
987
 
                                apc_warning(
988
 
                                        "apc_exists() expects a string or array of strings." TSRMLS_CC);
989
 
                        }
990
 
 
991
 
                        /* don't set values we didn't find */
992
 
            zend_hash_move_forward_ex(Z_ARRVAL_P(key), &hpos);
993
 
        }
994
 
        RETURN_ZVAL(result, 0, 1);
995
 
    } else {
996
 
        apc_warning("apc_exists() expects a string or array of strings." TSRMLS_CC);
997
 
    }
998
 
 
999
 
    RETURN_FALSE;
1000
 
}
1001
 
/* }}} */
1002
 
 
1003
 
/* {{{ proto mixed apc_delete(mixed keys)
1004
 
 */
1005
 
PHP_FUNCTION(apcu_delete) {
1006
 
    zval *keys;
1007
 
 
1008
 
    if (!APCG(enabled)) {
1009
 
                RETURN_FALSE;
1010
 
        }
1011
 
 
1012
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &keys) == FAILURE) {
1013
 
        return;
1014
 
    }
1015
 
 
1016
 
    if (Z_TYPE_P(keys) == IS_STRING) {
1017
 
        if (!Z_STRLEN_P(keys)) {
1018
 
                        RETURN_FALSE;
1019
 
                }
1020
 
 
1021
 
        if (apc_cache_delete(apc_user_cache, Z_STRVAL_P(keys), (Z_STRLEN_P(keys) + 1) TSRMLS_CC)) {
1022
 
            RETURN_TRUE;
1023
 
        } else {
1024
 
            RETURN_FALSE;
1025
 
        }
1026
 
 
1027
 
    } else if (Z_TYPE_P(keys) == IS_ARRAY) {
1028
 
        HashPosition hpos;
1029
 
        zval **hentry;
1030
 
 
1031
 
        array_init(return_value);
1032
 
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &hpos);
1033
 
 
1034
 
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void**)&hentry, &hpos) == SUCCESS) {
1035
 
            if (Z_TYPE_PP(hentry) != IS_STRING) {
1036
 
                apc_warning("apc_delete() expects a string, array of strings, or APCIterator instance." TSRMLS_CC);
1037
 
                add_next_index_zval(return_value, *hentry);
1038
 
                Z_ADDREF_PP(hentry);
1039
 
            } else if (apc_cache_delete(apc_user_cache, Z_STRVAL_PP(hentry), (Z_STRLEN_PP(hentry) + 1) TSRMLS_CC) != 1) {
1040
 
                add_next_index_zval(return_value, *hentry);
1041
 
                Z_ADDREF_PP(hentry);
1042
 
            }
1043
 
            zend_hash_move_forward_ex(Z_ARRVAL_P(keys), &hpos);
1044
 
        }
1045
 
    } else if (Z_TYPE_P(keys) == IS_OBJECT) {
1046
 
 
1047
 
        if (apc_iterator_delete(keys TSRMLS_CC)) {
1048
 
            RETURN_TRUE;
1049
 
        } else {
1050
 
            RETURN_FALSE;
1051
 
        }
1052
 
    } else {
1053
 
        apc_warning("apc_delete() expects a string, array of strings, or APCIterator instance." TSRMLS_CC);
1054
 
    }
1055
 
}
1056
 
/* }}} */
1057
 
 
1058
 
/* {{{ proto mixed apcu_bin_dump([array vars])
1059
 
    Returns a binary dump of the given user variables from the APC cache.
1060
 
    A NULL for vars signals a dump of every entry, while array() will dump nothing.
1061
 
 */
1062
 
PHP_FUNCTION(apcu_bin_dump) {
1063
 
 
1064
 
    zval *z_vars = NULL;
1065
 
    HashTable  *h_vars;
1066
 
    apc_bd_t *bd;
1067
 
 
1068
 
    if (!APCG(enabled)) {
1069
 
        apc_warning("APC is not enabled, apc_bin_dump not available." TSRMLS_CC);
1070
 
        RETURN_FALSE;
1071
 
    }
1072
 
 
1073
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &z_vars) == FAILURE) {
1074
 
        return;
1075
 
    }
1076
 
 
1077
 
    h_vars = z_vars ? Z_ARRVAL_P(z_vars) : NULL;
1078
 
    bd = apc_bin_dump(apc_user_cache, h_vars TSRMLS_CC);
1079
 
    if (bd) {
1080
 
        RETVAL_STRINGL((char*)bd, bd->size-1, 0);
1081
 
    } else {
1082
 
        apc_error("Unknown error encountered during apc_bin_dump." TSRMLS_CC);
1083
 
        RETVAL_NULL();
1084
 
    }
1085
 
 
1086
 
    return;
1087
 
}
1088
 
/* }}} */
1089
 
 
1090
 
#ifdef APC_FULL_BC
1091
 
/* {{{ proto mixed apc_bin_dump([array files [, array user_vars]])
1092
 
    Compatibility mode for old APC
1093
 
 */
1094
 
PHP_FUNCTION(apc_bin_dump) {
1095
 
 
1096
 
    zval *z_files = NULL, *z_user_vars = NULL;
1097
 
    HashTable *h_user_vars;
1098
 
    apc_bd_t *bd;
1099
 
 
1100
 
    if(!APCG(enabled)) {
1101
 
        apc_warning("APC is not enabled, apc_bin_dump not available." TSRMLS_CC);
1102
 
        RETURN_FALSE;
1103
 
    }
1104
 
 
1105
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!a!", &z_files, &z_user_vars) == FAILURE) {
1106
 
        return;
1107
 
    }
1108
 
 
1109
 
    h_user_vars = z_user_vars ? Z_ARRVAL_P(z_user_vars) : NULL;
1110
 
    bd = apc_bin_dump(apc_user_cache, h_user_vars TSRMLS_CC);
1111
 
    if(bd) {
1112
 
        RETVAL_STRINGL((char*)bd, bd->size-1, 0);
1113
 
    } else {
1114
 
        apc_error("Unknown error encountered during apc_bin_dump." TSRMLS_CC);
1115
 
        RETVAL_NULL();
1116
 
    }
1117
 
 
1118
 
    return;
1119
 
}
1120
 
/* }}} */
1121
 
#endif
1122
 
 
1123
 
/* {{{ proto mixed apcu_bin_dumpfile(array vars, string filename, [int flags [, resource context]])
1124
 
    Output a binary dump of the given user variables from the APC cache to the named file.
1125
 
 */
1126
 
PHP_FUNCTION(apcu_bin_dumpfile) {
1127
 
 
1128
 
    zval *z_vars = NULL;
1129
 
    HashTable *h_vars;
1130
 
    char *filename = NULL;
1131
 
    int filename_len;
1132
 
    long flags=0;
1133
 
    zval *zcontext = NULL;
1134
 
    php_stream_context *context = NULL;
1135
 
    php_stream *stream;
1136
 
    int numbytes = 0;
1137
 
    apc_bd_t *bd;
1138
 
 
1139
 
    if (!APCG(enabled)) {
1140
 
        apc_warning("APC is not enabled, apc_bin_dumpfile not available." TSRMLS_CC);
1141
 
        RETURN_FALSE;
1142
 
    }
1143
 
 
1144
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!s|lr!", &z_vars, &filename, &filename_len, &flags, &zcontext) == FAILURE) {
1145
 
        return;
1146
 
    }
1147
 
 
1148
 
    if (!filename_len) {
1149
 
        apc_error("apc_bin_dumpfile filename argument must be a valid filename." TSRMLS_CC);
1150
 
        RETURN_FALSE;
1151
 
    }
1152
 
 
1153
 
    h_vars = z_vars ? Z_ARRVAL_P(z_vars) : NULL;
1154
 
    bd = apc_bin_dump(apc_user_cache, h_vars TSRMLS_CC);
1155
 
    if (!bd) {
1156
 
        apc_error("Unknown error encountered during apc_bin_dumpfile." TSRMLS_CC);
1157
 
        RETURN_FALSE;
1158
 
    }
1159
 
 
1160
 
 
1161
 
    /* Most of the following has been taken from the file_get/put_contents functions */
1162
 
 
1163
 
    context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
1164
 
    stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb",
1165
 
                                            ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
1166
 
    if (stream == NULL) {
1167
 
        efree(bd);
1168
 
        apc_error("Unable to write to file in apc_bin_dumpfile." TSRMLS_CC);
1169
 
        RETURN_FALSE;
1170
 
    }
1171
 
 
1172
 
    if (flags & LOCK_EX && php_stream_lock(stream, LOCK_EX)) {
1173
 
        php_stream_close(stream);
1174
 
        efree(bd);
1175
 
        apc_error("Unable to get a lock on file in apc_bin_dumpfile." TSRMLS_CC);
1176
 
        RETURN_FALSE;
1177
 
    }
1178
 
 
1179
 
    numbytes = php_stream_write(stream, (char*)bd, bd->size);
1180
 
    if (numbytes != bd->size) {
1181
 
        numbytes = -1;
1182
 
    }
1183
 
 
1184
 
    php_stream_close(stream);
1185
 
    efree(bd);
1186
 
 
1187
 
    if (numbytes < 0) {
1188
 
        apc_error("Only %d of %d bytes written, possibly out of free disk space" TSRMLS_CC, numbytes, bd->size);
1189
 
        RETURN_FALSE;
1190
 
    }
1191
 
 
1192
 
    RETURN_LONG(numbytes);
1193
 
}
1194
 
/* }}} */
1195
 
 
1196
 
#ifdef APC_FULL_BC
1197
 
/* {{{ proto mixed apc_bin_dumpfile(array files, array user_vars, string filename, [int flags [, resource context]])
1198
 
    Compatibility mode for old APC
1199
 
 */
1200
 
PHP_FUNCTION(apc_bin_dumpfile) {
1201
 
 
1202
 
    zval *z_files = NULL, *z_user_vars = NULL;
1203
 
    HashTable *h_user_vars;
1204
 
    char *filename = NULL;
1205
 
    int filename_len;
1206
 
    long flags=0;
1207
 
    zval *zcontext = NULL;
1208
 
    php_stream_context *context = NULL;
1209
 
    php_stream *stream;
1210
 
    int numbytes = 0;
1211
 
    apc_bd_t *bd;
1212
 
 
1213
 
    if(!APCG(enabled)) {
1214
 
        apc_warning("APC is not enabled, apc_bin_dumpfile not available." TSRMLS_CC);
1215
 
        RETURN_FALSE;
1216
 
    }
1217
 
 
1218
 
 
1219
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!s|lr!", &z_files, &z_user_vars, &filename, &filename_len, &flags, &zcontext) == 
1220
 
FAILURE) {
1221
 
        return;
1222
 
    }
1223
 
 
1224
 
    if(!filename_len) {
1225
 
        apc_error("apc_bin_dumpfile filename argument must be a valid filename." TSRMLS_CC);
1226
 
        RETURN_FALSE;
1227
 
    }
1228
 
 
1229
 
    h_user_vars = z_user_vars ? Z_ARRVAL_P(z_user_vars) : NULL;
1230
 
    bd = apc_bin_dump(apc_user_cache, h_user_vars TSRMLS_CC);
1231
 
    if(!bd) {
1232
 
        apc_error("Unknown error encountered during apc_bin_dumpfile." TSRMLS_CC);
1233
 
        RETURN_FALSE;
1234
 
    }
1235
 
 
1236
 
 
1237
 
    /* Most of the following has been taken from the file_get/put_contents functions */
1238
 
 
1239
 
    context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
1240
 
    stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb",
1241
 
                                            ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
1242
 
    if (stream == NULL) {
1243
 
        efree(bd);
1244
 
        apc_error("Unable to write to file in apc_bin_dumpfile." TSRMLS_CC);
1245
 
        RETURN_FALSE;
1246
 
    }
1247
 
 
1248
 
    if (flags & LOCK_EX && php_stream_lock(stream, LOCK_EX)) {
1249
 
        php_stream_close(stream);
1250
 
        efree(bd);
1251
 
        apc_error("Unable to get a lock on file in apc_bin_dumpfile." TSRMLS_CC);
1252
 
        RETURN_FALSE;
1253
 
    }
1254
 
 
1255
 
    numbytes = php_stream_write(stream, (char*)bd, bd->size);
1256
 
    if(numbytes != bd->size) {
1257
 
        numbytes = -1;
1258
 
    }
1259
 
 
1260
 
    php_stream_close(stream);
1261
 
    efree(bd);
1262
 
 
1263
 
    if(numbytes < 0) {
1264
 
        apc_error("Only %d of %d bytes written, possibly out of free disk space" TSRMLS_CC, numbytes, bd->size);
1265
 
        RETURN_FALSE;
1266
 
    }
1267
 
 
1268
 
    RETURN_LONG(numbytes);
1269
 
}
1270
 
/* }}} */
1271
 
#endif
1272
 
 
1273
 
/* {{{ proto mixed apcu_bin_load(string data, [int flags])
1274
 
    Load the given binary dump into the APC file/user cache.
1275
 
 */
1276
 
PHP_FUNCTION(apcu_bin_load) {
1277
 
 
1278
 
    int data_len;
1279
 
    char *data;
1280
 
    long flags = 0;
1281
 
 
1282
 
    if (!APCG(enabled)) {
1283
 
        apc_warning("APC is not enabled, apc_bin_load not available." TSRMLS_CC);
1284
 
        RETURN_FALSE;
1285
 
    }
1286
 
 
1287
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &flags) == FAILURE) {
1288
 
        return;
1289
 
    }
1290
 
 
1291
 
    if (!data_len || data_len != ((apc_bd_t*)data)->size -1) {
1292
 
        apc_error("apc_bin_load string argument does not appear to be a valid APC binary dump due to size (%d vs expected %d)." TSRMLS_CC, data_len, 
1293
 
((apc_bd_t*)data)->size -1);
1294
 
        RETURN_FALSE;
1295
 
    }
1296
 
 
1297
 
    apc_bin_load(apc_user_cache, (apc_bd_t*)data, (int)flags TSRMLS_CC);
1298
 
 
1299
 
    RETURN_TRUE;
1300
 
}
1301
 
/* }}} */
1302
 
 
1303
 
/* {{{ proto mixed apc_bin_loadfile(string filename, [resource context, [int flags]])
1304
 
    Load the given binary dump from the named file into the APC file/user cache.
1305
 
 */
1306
 
PHP_FUNCTION(apcu_bin_loadfile) {
1307
 
 
1308
 
    char *filename;
1309
 
    int filename_len;
1310
 
    zval *zcontext = NULL;
1311
 
    long flags = 0;
1312
 
    php_stream_context *context = NULL;
1313
 
    php_stream *stream;
1314
 
    char *data;
1315
 
    int len;
1316
 
 
1317
 
    if (!APCG(enabled)) {
1318
 
        apc_warning("APC is not enabled, apc_bin_loadfile not available." TSRMLS_CC);
1319
 
        RETURN_FALSE;
1320
 
    }
1321
 
 
1322
 
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r!l", &filename, &filename_len, &zcontext, &flags) == FAILURE) {
1323
 
        return;
1324
 
    }
1325
 
 
1326
 
    if (!filename_len) {
1327
 
        apc_error("apc_bin_loadfile filename argument must be a valid filename." TSRMLS_CC);
1328
 
        RETURN_FALSE;
1329
 
    }
1330
 
 
1331
 
    context = php_stream_context_from_zval(zcontext, 0);
1332
 
    stream = php_stream_open_wrapper_ex(filename, "rb",
1333
 
            ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
1334
 
    if (!stream) {
1335
 
        apc_error("Unable to read from file in apc_bin_loadfile." TSRMLS_CC);
1336
 
        RETURN_FALSE;
1337
 
    }
1338
 
 
1339
 
    len = php_stream_copy_to_mem(stream, &data, PHP_STREAM_COPY_ALL, 0);
1340
 
    if (len == 0) {
1341
 
        apc_warning("File passed to apc_bin_loadfile was empty: %s." TSRMLS_CC, filename);
1342
 
        RETURN_FALSE;
1343
 
    } else if (len < 0) {
1344
 
        apc_warning("Error reading file passed to apc_bin_loadfile: %s." TSRMLS_CC, filename);
1345
 
        RETURN_FALSE;
1346
 
    } else if (len != ((apc_bd_t*)data)->size) {
1347
 
        apc_warning("file passed to apc_bin_loadfile does not appear to be valid due to size (%d vs expected %d)." TSRMLS_CC, len, 
1348
 
((apc_bd_t*)data)->size -1);
1349
 
        RETURN_FALSE;
1350
 
    }
1351
 
    php_stream_close(stream);
1352
 
 
1353
 
    apc_bin_load(apc_user_cache, (apc_bd_t*)data, (int)flags TSRMLS_CC);
1354
 
    efree(data);
1355
 
 
1356
 
    RETURN_TRUE;
1357
 
}
1358
 
/* }}} */
1359
 
 
1360
 
/* {{{ arginfo */
1361
 
#if (PHP_MAJOR_VERSION >= 6 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3))
1362
 
# define PHP_APC_ARGINFO
1363
 
#else
1364
 
# define PHP_APC_ARGINFO static
1365
 
#endif
1366
 
 
1367
 
PHP_APC_ARGINFO
1368
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_store, 0, 0, 2)
1369
 
    ZEND_ARG_INFO(0, key)
1370
 
    ZEND_ARG_INFO(0, var)
1371
 
    ZEND_ARG_INFO(0, ttl)
1372
 
ZEND_END_ARG_INFO()
1373
 
 
1374
 
PHP_APC_ARGINFO
1375
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_enabled, 0, 0, 0)
1376
 
ZEND_END_ARG_INFO()
1377
 
 
1378
 
#ifdef APC_FULL_BC
1379
 
PHP_APC_ARGINFO
1380
 
/* this will generate different reflection but retains functional compatibility */
1381
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_cache_info, 0, 0, 0)
1382
 
    ZEND_ARG_INFO(0, type)
1383
 
    ZEND_ARG_INFO(0, limited)
1384
 
ZEND_END_ARG_INFO()
1385
 
PHP_APC_ARGINFO
1386
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_clear_cache, 0, 0, 0)
1387
 
    ZEND_ARG_INFO(0, cache)
1388
 
ZEND_END_ARG_INFO()
1389
 
#else
1390
 
PHP_APC_ARGINFO
1391
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_cache_info, 0, 0, 0)
1392
 
    ZEND_ARG_INFO(0, limited)
1393
 
ZEND_END_ARG_INFO()
1394
 
 
1395
 
PHP_APC_ARGINFO
1396
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_clear_cache, 0, 0, 0)
1397
 
ZEND_END_ARG_INFO()
1398
 
#endif
1399
 
 
1400
 
PHP_APC_ARGINFO
1401
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_key_info, 0, 0, 1)
1402
 
    ZEND_ARG_INFO(0, key)
1403
 
ZEND_END_ARG_INFO()
1404
 
 
1405
 
PHP_APC_ARGINFO
1406
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_sma_info, 0, 0, 0)
1407
 
    ZEND_ARG_INFO(0, limited)
1408
 
ZEND_END_ARG_INFO()
1409
 
 
1410
 
PHP_APC_ARGINFO
1411
 
ZEND_BEGIN_ARG_INFO(arginfo_apcu_delete, 0)
1412
 
    ZEND_ARG_INFO(0, keys)
1413
 
ZEND_END_ARG_INFO()
1414
 
 
1415
 
PHP_APC_ARGINFO
1416
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_fetch, 0, 0, 1)
1417
 
    ZEND_ARG_INFO(0, key)
1418
 
    ZEND_ARG_INFO(1, success)
1419
 
ZEND_END_ARG_INFO()
1420
 
 
1421
 
 
1422
 
PHP_APC_ARGINFO
1423
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_inc, 0, 0, 1)
1424
 
    ZEND_ARG_INFO(0, key)
1425
 
    ZEND_ARG_INFO(0, step)
1426
 
    ZEND_ARG_INFO(1, success)
1427
 
ZEND_END_ARG_INFO()
1428
 
 
1429
 
PHP_APC_ARGINFO
1430
 
ZEND_BEGIN_ARG_INFO(arginfo_apcu_cas, 0)
1431
 
    ZEND_ARG_INFO(0, key)
1432
 
    ZEND_ARG_INFO(0, old)
1433
 
    ZEND_ARG_INFO(0, new)
1434
 
ZEND_END_ARG_INFO()
1435
 
 
1436
 
PHP_APC_ARGINFO
1437
 
ZEND_BEGIN_ARG_INFO(arginfo_apcu_exists, 0)
1438
 
    ZEND_ARG_INFO(0, keys)
1439
 
ZEND_END_ARG_INFO()
1440
 
 
1441
 
PHP_APC_ARGINFO
1442
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bin_dump, 0, 0, 0)
1443
 
    ZEND_ARG_INFO(0, user_vars)
1444
 
ZEND_END_ARG_INFO()
1445
 
 
1446
 
PHP_APC_ARGINFO
1447
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bin_dumpfile, 0, 0, 2)
1448
 
    ZEND_ARG_INFO(0, user_vars)
1449
 
    ZEND_ARG_INFO(0, filename)
1450
 
    ZEND_ARG_INFO(0, flags)
1451
 
    ZEND_ARG_INFO(0, context)
1452
 
ZEND_END_ARG_INFO()
1453
 
 
1454
 
PHP_APC_ARGINFO
1455
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bin_load, 0, 0, 1)
1456
 
    ZEND_ARG_INFO(0, data)
1457
 
    ZEND_ARG_INFO(0, flags)
1458
 
ZEND_END_ARG_INFO()
1459
 
 
1460
 
PHP_APC_ARGINFO
1461
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apcu_bin_loadfile, 0, 0, 1)
1462
 
    ZEND_ARG_INFO(0, filename)
1463
 
    ZEND_ARG_INFO(0, context)
1464
 
    ZEND_ARG_INFO(0, flags)
1465
 
ZEND_END_ARG_INFO()
1466
 
 
1467
 
 
1468
 
#ifdef APC_FULL_BC
1469
 
PHP_APC_ARGINFO
1470
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apc_bin_dump, 0, 0, 0)
1471
 
    ZEND_ARG_INFO(0, files)
1472
 
    ZEND_ARG_INFO(0, user_vars)
1473
 
ZEND_END_ARG_INFO()
1474
 
 
1475
 
PHP_APC_ARGINFO
1476
 
ZEND_BEGIN_ARG_INFO_EX(arginfo_apc_bin_dumpfile, 0, 0, 3)
1477
 
    ZEND_ARG_INFO(0, files)
1478
 
    ZEND_ARG_INFO(0, user_vars)
1479
 
    ZEND_ARG_INFO(0, filename)
1480
 
    ZEND_ARG_INFO(0, flags)
1481
 
    ZEND_ARG_INFO(0, context)
1482
 
ZEND_END_ARG_INFO()
1483
 
#endif
1484
 
/* }}} */
1485
 
 
1486
 
/* {{{ apcu_functions[] */
1487
 
zend_function_entry apcu_functions[] = {
1488
 
    PHP_FE(apcu_cache_info,         arginfo_apcu_cache_info)
1489
 
    PHP_FE(apcu_clear_cache,        arginfo_apcu_clear_cache)
1490
 
    PHP_FE(apcu_sma_info,           arginfo_apcu_sma_info)
1491
 
    PHP_FE(apcu_key_info,           arginfo_apcu_key_info)
1492
 
    PHP_FE(apcu_enabled,            arginfo_apcu_enabled)
1493
 
    PHP_FE(apcu_store,              arginfo_apcu_store)
1494
 
    PHP_FE(apcu_fetch,              arginfo_apcu_fetch)
1495
 
    PHP_FE(apcu_delete,             arginfo_apcu_delete)
1496
 
    PHP_FE(apcu_add,                arginfo_apcu_store)
1497
 
    PHP_FE(apcu_inc,                arginfo_apcu_inc)
1498
 
    PHP_FE(apcu_dec,                arginfo_apcu_inc)
1499
 
    PHP_FE(apcu_cas,                arginfo_apcu_cas)
1500
 
    PHP_FE(apcu_exists,             arginfo_apcu_exists)
1501
 
    PHP_FE(apcu_bin_dump,           arginfo_apcu_bin_dump)
1502
 
    PHP_FE(apcu_bin_load,           arginfo_apcu_bin_load)
1503
 
    PHP_FE(apcu_bin_dumpfile,       arginfo_apcu_bin_dumpfile)
1504
 
    PHP_FE(apcu_bin_loadfile,       arginfo_apcu_bin_loadfile)
1505
 
    {NULL, NULL, NULL}
1506
 
};
1507
 
/* }}} */
1508
 
 
1509
 
/* {{{ module definition structure */
1510
 
 
1511
 
zend_module_entry apcu_module_entry = {
1512
 
    STANDARD_MODULE_HEADER,
1513
 
    PHP_APCU_EXTNAME,
1514
 
    apcu_functions,
1515
 
    PHP_MINIT(apcu),
1516
 
    PHP_MSHUTDOWN(apcu),
1517
 
    PHP_RINIT(apcu),
1518
 
    NULL,
1519
 
    PHP_MINFO(apcu),
1520
 
    PHP_APCU_VERSION,
1521
 
    STANDARD_MODULE_PROPERTIES
1522
 
};
1523
 
 
1524
 
#ifdef APC_FULL_BC
1525
 
 
1526
 
PHP_MINFO_FUNCTION(apc)
1527
 
{
1528
 
        php_info_print_table_start();
1529
 
        php_info_print_table_row(2, "APC support", "Emulated");
1530
 
        php_info_print_table_end();
1531
 
}
1532
 
 
1533
 
/* {{{ apc_functions[] */
1534
 
zend_function_entry apc_functions[] = {
1535
 
    PHP_FALIAS(apc_cache_info,   apcu_cache_info,   arginfo_apcu_cache_info)
1536
 
    PHP_FALIAS(apc_clear_cache,  apcu_clear_cache,  arginfo_apcu_clear_cache)
1537
 
    PHP_FALIAS(apc_sma_info,     apcu_sma_info,     arginfo_apcu_sma_info)
1538
 
    PHP_FALIAS(apc_store,        apcu_store,        arginfo_apcu_store)
1539
 
    PHP_FALIAS(apc_fetch,        apcu_fetch,        arginfo_apcu_fetch)
1540
 
    PHP_FALIAS(apc_delete,       apcu_delete,       arginfo_apcu_delete)
1541
 
    PHP_FALIAS(apc_add,          apcu_add,          arginfo_apcu_store)
1542
 
    PHP_FALIAS(apc_inc,          apcu_inc,          arginfo_apcu_inc)
1543
 
    PHP_FALIAS(apc_dec,          apcu_dec,          arginfo_apcu_inc)
1544
 
    PHP_FALIAS(apc_cas,          apcu_cas,          arginfo_apcu_cas)
1545
 
    PHP_FALIAS(apc_exists,       apcu_exists,       arginfo_apcu_exists)
1546
 
    PHP_FE(apc_bin_dump,                            arginfo_apc_bin_dump)
1547
 
    PHP_FE(apc_bin_dumpfile,                        arginfo_apc_bin_dumpfile)
1548
 
    PHP_FALIAS(apc_bin_load,     apcu_bin_load,     arginfo_apcu_bin_load)
1549
 
    PHP_FALIAS(apc_bin_loadfile, apcu_bin_loadfile, arginfo_apcu_bin_loadfile)
1550
 
    {NULL, NULL, NULL}
1551
 
};
1552
 
 
1553
 
zend_module_entry apc_module_entry = {
1554
 
        STANDARD_MODULE_HEADER,
1555
 
        "apc",
1556
 
        apc_functions,
1557
 
        NULL,
1558
 
        NULL,
1559
 
        NULL,
1560
 
        NULL,
1561
 
        PHP_MINFO(apc),
1562
 
        PHP_APCU_VERSION,
1563
 
        STANDARD_MODULE_PROPERTIES,
1564
 
};
1565
 
 
1566
 
static void apc_init(INIT_FUNC_ARGS)
1567
 
{
1568
 
        zend_register_internal_module(&apc_module_entry TSRMLS_CC);
1569
 
}
1570
 
 
1571
 
#endif
1572
 
 
1573
 
 
1574
 
#ifdef COMPILE_DL_APCU
1575
 
ZEND_GET_MODULE(apcu)
1576
 
#endif
1577
 
/* }}} */
1578
 
 
1579
 
/*
1580
 
 * Local variables:
1581
 
 * tab-width: 4
1582
 
 * c-basic-offset: 4
1583
 
 * End:
1584
 
 * vim>600: expandtab sw=4 ts=4 sts=4 fdm=marker
1585
 
 * vim<600: expandtab sw=4 ts=4 sts=4
1586
 
 */