cvs: pecl /apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h php_apc.c
| From: | Rasmus Lerdorf | Date: | Sun, 12 Sep 2004 14:31:45 +0000 |
| Subject: | cvs: pecl /apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h php_apc.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1824@lists.php.net to get a copy of this message | ||
rasmus Sun Sep 12 10:31:45 2004 EDT
Modified files:
/pecl/apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h
php_apc.c
Log:
Added apc_define_constants() and apc_load_constants() to speed up apps
that have hundreds of user-space constants.
http://cvs.php.net/diff.php/pecl/apc/apc_cache.c?r1=3.68&r2=3.69&ty=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.68 pecl/apc/apc_cache.c:3.69 --- pecl/apc/apc_cache.c:3.68 Sun Sep 12 02:12:17 2004 +++ pecl/apc/apc_cache.c Sun Sep 12 10:31:44 2004 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.c,v 3.68 2004/09/12 06:12:17 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.69 2004/09/12 14:31:44 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -532,7 +532,7 @@ /* }}} */ /* {{{ apc_cache_make_user_key */ -int apc_cache_make_user_key(apc_cache_key_t* key, const char* identifier, time_t t) +int apc_cache_make_user_key(apc_cache_key_t* key, const char* identifier, const time_t t TSRMLS_DC) { assert(key != NULL); @@ -581,7 +581,7 @@ /* }}} */ /* {{{ apc_cache_make_user_entry */ -apc_cache_entry_t* apc_cache_make_user_entry(const char* info, zval* val, unsigned int ttl) +apc_cache_entry_t* apc_cache_make_user_entry(const char* info, const zval* val, const unsigned int ttl) { apc_cache_entry_t* entry; http://cvs.php.net/diff.php/pecl/apc/apc_cache.h?r1=3.19&r2=3.20&ty=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.19 pecl/apc/apc_cache.h:3.20 --- pecl/apc/apc_cache.h:3.19 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_cache.h Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.h,v 3.19 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.20 2004/09/12 14:31:44 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -185,7 +185,7 @@ * apc_cache_make_user_entry creates an apc_cache_entry_t object given an info string * and the zval to be stored. */ -extern apc_cache_entry_t* apc_cache_make_user_entry(const char* info, zval *val, unsigned int ttl); +extern apc_cache_entry_t* apc_cache_make_user_entry(const char* info, const zval *val, const unsigned int ttl); /* * Frees all memory associated with an object returned by apc_cache_make_entry http://cvs.php.net/diff.php/pecl/apc/apc_compile.c?r1=3.12&r2=3.13&ty=u Index: pecl/apc/apc_compile.c diff -u pecl/apc/apc_compile.c:3.12 pecl/apc/apc_compile.c:3.13 --- pecl/apc/apc_compile.c:3.12 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_compile.c Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.c,v 3.12 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_compile.c,v 3.13 2004/09/12 14:31:44 rasmus Exp $ */ #include "apc_compile.h" #include "apc_globals.h" @@ -37,8 +37,8 @@ * (passed as the second argument). They also optionally allocate space for * the destination data structure if the first argument is null. */ -static zval** my_copy_zval_ptr(zval**, zval**, apc_malloc_t, apc_free_t); -static zval* my_copy_zval(zval*, zval*, apc_malloc_t, apc_free_t); +static zval** my_copy_zval_ptr(zval**, const zval**, apc_malloc_t, apc_free_t); +static zval* my_copy_zval(zval*, const zval*, apc_malloc_t, apc_free_t); static znode* my_copy_znode(znode*, znode*, apc_malloc_t, apc_free_t); static zend_op* my_copy_zend_op(zend_op*, zend_op*, apc_malloc_t, apc_free_t); static zend_function* my_copy_function(zend_function*, zend_function*, apc_malloc_t, apc_free_t); @@ -169,7 +169,7 @@ /* }}} */ /* {{{ my_copy_zval_ptr */ -static zval** my_copy_zval_ptr(zval** dst, zval** src, apc_malloc_t allocate, apc_free_t deallocate) +static zval** my_copy_zval_ptr(zval** dst, const zval** src, apc_malloc_t allocate, apc_free_t deallocate) { int local_dst_alloc = 0; @@ -190,7 +190,7 @@ /* }}} */ /* {{{ my_copy_zval */ -static zval* my_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate) +static zval* my_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate) { assert(dst != NULL); assert(src != NULL); @@ -577,7 +577,7 @@ /* }}} */ /* {{{ apc_copy_zval */ -zval* apc_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) +zval* apc_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) { int local_dst_alloc = 0; assert(src != NULL); http://cvs.php.net/diff.php/pecl/apc/apc_compile.h?r1=3.5&r2=3.6&ty=u Index: pecl/apc/apc_compile.h diff -u pecl/apc/apc_compile.h:3.5 pecl/apc/apc_compile.h:3.6 --- pecl/apc/apc_compile.h:3.5 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_compile.h Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.h,v 3.5 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_compile.h,v 3.6 2004/09/12 14:31:44 rasmus Exp $ */ #ifndef APC_COMPILE_H #define APC_COMPILE_H @@ -56,7 +56,7 @@ extern zend_class_entry* apc_copy_class_entry(zend_class_entry* dst, zend_class_entry* src, apc_malloc_t allocate, apc_free_t deallocate); extern apc_function_t* apc_copy_new_functions(int old_count, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); extern apc_class_t* apc_copy_new_classes(zend_op_array* op_array, int old_count, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); -extern zval* apc_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); +extern zval* apc_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); /* * Deallocation functions corresponding to the copy functions above. http://cvs.php.net/diff.php/pecl/apc/php_apc.c?r1=3.36&r2=3.37&ty=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.36 pecl/apc/php_apc.c:3.37 --- pecl/apc/php_apc.c:3.36 Sun Sep 12 09:20:56 2004 +++ pecl/apc/php_apc.c Sun Sep 12 10:31:44 2004 @@ -2,19 +2,20 @@ +----------------------------------------------------------------------+ | Copyright (c) 2002 by Community Connect Inc. All rights reserved. | +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | + | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | - | http://www.php.net/license/3_0.txt. | + | http://www.php.net/license/3_0.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 | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | + | Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_apc.c,v 3.36 2004/09/12 13:20:56 rasmus Exp $ */ +/* $Id: php_apc.c,v 3.37 2004/09/12 14:31:44 rasmus Exp $ */ #ifdef PHP_WIN32 /* XXX lame hack, for some reason, the ini entries are all messed @@ -49,6 +50,8 @@ PHP_FUNCTION(apc_sma_info); PHP_FUNCTION(apc_store); PHP_FUNCTION(apc_fetch); +PHP_FUNCTION(apc_define_constants); +PHP_FUNCTION(apc_load_constants); /* }}} */ /* {{{ ZEND_DECLARE_MODULE_GLOBALS(apc) */ @@ -122,7 +125,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.36 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.37 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); DISPLAY_INI_ENTRIES(); php_info_print_table_end(); @@ -335,29 +338,18 @@ } /* }}} */ -/* {{{ proto int apc_store(string key, zval var [, ttl ]) - */ -PHP_FUNCTION(apc_store) { - zval *val; - char *strkey; - int strkey_len; - apc_cache_entry_t *entry; +static int _apc_store(const char *strkey, const zval *val, const unsigned int ttl TSRMLS_DC) { + apc_cache_entry_t *entry; apc_cache_key_t key; - long ttl = 0L; time_t t; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|l", &strkey, &strkey_len, &val, &ttl) == FAILURE) { - return; - } - - - if (!(entry = apc_cache_make_user_entry(strkey, val, (unsigned int)ttl))) { - RETURN_FALSE; + if (!(entry = apc_cache_make_user_entry(strkey, val, ttl))) { + return 0; } if (!apc_cache_make_user_key(&key, strkey TSRMLS_CC)) { apc_cache_free_entry(entry); - RETURN_FALSE; + return 1; } #if HAVE_APACHE @@ -371,10 +363,28 @@ if (!apc_cache_user_insert(APCG(user_cache), key, entry, t)) { apc_cache_free_user_key(&key); apc_cache_free_entry(entry); - RETURN_FALSE; + return 0; } - RETURN_TRUE; + return 1; +} + +/* {{{ proto int apc_store(string key, zval var [, ttl ]) + */ +PHP_FUNCTION(apc_store) { + zval *val; + char *strkey; + int strkey_len; + long ttl = 0L; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|l", &strkey, &strkey_len, &val, &ttl) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + + if(_apc_store(strkey, val, (unsigned int)ttl TSRMLS_CC)) RETURN_TRUE; + RETURN_FALSE; } /* }}} */ @@ -390,6 +400,8 @@ return; } + if(!strkey_len) RETURN_FALSE; + #if HAVE_APACHE /* Save a syscall here under Apache. This should actually be a SAPI call instead * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ @@ -423,6 +435,91 @@ return; } + if(!strkey_len) RETURN_FALSE; + + if(apc_cache_user_delete(APCG(user_cache), strkey, strkey_len)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +static void _apc_define_constants(zval *constants, zend_bool case_sensitive) { + char *const_key; + int const_key_len; + zval **entry; + HashPosition pos; + + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(constants), &pos); + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(constants), (void**)&entry, &pos) == SUCCESS) { + zend_constant c; + int key_type; + ulong num_key; + + key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(constants), &const_key, &const_key_len, &num_key, 0, &pos); + if(key_type != HASH_KEY_IS_STRING) { + continue; + } + switch(Z_TYPE_PP(entry)) { + case IS_LONG: + case IS_DOUBLE: + case IS_STRING: + case IS_BOOL: + case IS_RESOURCE: + case IS_NULL: + break; + default: + continue; + } + c.value = **entry; + zval_copy_ctor(&c.value); + c.flags = case_sensitive; + c.name = zend_strndup(const_key, const_key_len); + c.name_len = const_key_len; + zend_register_constant(&c TSRMLS_CC); + + zend_hash_move_forward_ex(Z_ARRVAL_P(constants), &pos); + } +} + +/* {{{ proto mixed apc_define_constants(string key, array constants [,bool case-sensitive]) + */ +PHP_FUNCTION(apc_define_constants) { + char *strkey; + int strkey_len; + ulong num_key; + zval *constants = NULL; + zend_bool case_sensitive = 1; + int argc = ZEND_NUM_ARGS(); + + if (zend_parse_parameters(argc TSRMLS_CC, "sa|b", &strkey, &strkey_len, &constants, &case_sensitive) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + + _apc_define_constants(constants, case_sensitive); + + if(_apc_store(strkey, constants, 0 TSRMLS_CC)) RETURN_TRUE; + RETURN_FALSE; +} /* }}} */ + +/* {{{ proto mixed apc_load_constants(string key [, bool case-sensitive]) + */ +PHP_FUNCTION(apc_load_constants) { + char *strkey; + int strkey_len; + apc_cache_entry_t* entry; + time_t t; + zend_bool case_sensitive = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &strkey, &strkey_len, &case_sensitive) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + #if HAVE_APACHE /* Save a syscall here under Apache. This should actually be a SAPI call instead * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ @@ -431,7 +528,11 @@ t = time(0); #endif - if(apc_cache_user_delete(APCG(user_cache), strkey, strkey_len)) { + entry = apc_cache_user_find(APCG(user_cache), strkey, strkey_len, t); + + if(entry) { + apc_stack_push(APCG(user_cache_stack), entry); + _apc_define_constants(entry->data.user.val, case_sensitive); RETURN_TRUE; } else { RETURN_FALSE; @@ -447,6 +548,8 @@ PHP_FE(apc_store, NULL) PHP_FE(apc_fetch, NULL) PHP_FE(apc_delete, NULL) + PHP_FE(apc_define_constants, NULL) + PHP_FE(apc_load_constants, NULL) {NULL, NULL, NULL} }; /* }}} */
http://cvs.php.net/diff.php/pecl/apc/apc_cache.c?r1=3.68&r2=3.69&ty=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.68 pecl/apc/apc_cache.c:3.69 --- pecl/apc/apc_cache.c:3.68 Sun Sep 12 02:12:17 2004 +++ pecl/apc/apc_cache.c Sun Sep 12 10:31:44 2004 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.c,v 3.68 2004/09/12 06:12:17 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.69 2004/09/12 14:31:44 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -532,7 +532,7 @@ /* }}} */ /* {{{ apc_cache_make_user_key */ -int apc_cache_make_user_key(apc_cache_key_t* key, const char* identifier, time_t t) +int apc_cache_make_user_key(apc_cache_key_t* key, const char* identifier, const time_t t TSRMLS_DC) { assert(key != NULL); @@ -581,7 +581,7 @@ /* }}} */ /* {{{ apc_cache_make_user_entry */ -apc_cache_entry_t* apc_cache_make_user_entry(const char* info, zval* val, unsigned int ttl) +apc_cache_entry_t* apc_cache_make_user_entry(const char* info, const zval* val, const unsigned int ttl) { apc_cache_entry_t* entry; http://cvs.php.net/diff.php/pecl/apc/apc_cache.h?r1=3.19&r2=3.20&ty=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.19 pecl/apc/apc_cache.h:3.20 --- pecl/apc/apc_cache.h:3.19 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_cache.h Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.h,v 3.19 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.20 2004/09/12 14:31:44 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -185,7 +185,7 @@ * apc_cache_make_user_entry creates an apc_cache_entry_t object given an info string * and the zval to be stored. */ -extern apc_cache_entry_t* apc_cache_make_user_entry(const char* info, zval *val, unsigned int ttl); +extern apc_cache_entry_t* apc_cache_make_user_entry(const char* info, const zval *val, const unsigned int ttl); /* * Frees all memory associated with an object returned by apc_cache_make_entry http://cvs.php.net/diff.php/pecl/apc/apc_compile.c?r1=3.12&r2=3.13&ty=u Index: pecl/apc/apc_compile.c diff -u pecl/apc/apc_compile.c:3.12 pecl/apc/apc_compile.c:3.13 --- pecl/apc/apc_compile.c:3.12 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_compile.c Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.c,v 3.12 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_compile.c,v 3.13 2004/09/12 14:31:44 rasmus Exp $ */ #include "apc_compile.h" #include "apc_globals.h" @@ -37,8 +37,8 @@ * (passed as the second argument). They also optionally allocate space for * the destination data structure if the first argument is null. */ -static zval** my_copy_zval_ptr(zval**, zval**, apc_malloc_t, apc_free_t); -static zval* my_copy_zval(zval*, zval*, apc_malloc_t, apc_free_t); +static zval** my_copy_zval_ptr(zval**, const zval**, apc_malloc_t, apc_free_t); +static zval* my_copy_zval(zval*, const zval*, apc_malloc_t, apc_free_t); static znode* my_copy_znode(znode*, znode*, apc_malloc_t, apc_free_t); static zend_op* my_copy_zend_op(zend_op*, zend_op*, apc_malloc_t, apc_free_t); static zend_function* my_copy_function(zend_function*, zend_function*, apc_malloc_t, apc_free_t); @@ -169,7 +169,7 @@ /* }}} */ /* {{{ my_copy_zval_ptr */ -static zval** my_copy_zval_ptr(zval** dst, zval** src, apc_malloc_t allocate, apc_free_t deallocate) +static zval** my_copy_zval_ptr(zval** dst, const zval** src, apc_malloc_t allocate, apc_free_t deallocate) { int local_dst_alloc = 0; @@ -190,7 +190,7 @@ /* }}} */ /* {{{ my_copy_zval */ -static zval* my_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate) +static zval* my_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate) { assert(dst != NULL); assert(src != NULL); @@ -577,7 +577,7 @@ /* }}} */ /* {{{ apc_copy_zval */ -zval* apc_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) +zval* apc_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) { int local_dst_alloc = 0; assert(src != NULL); http://cvs.php.net/diff.php/pecl/apc/apc_compile.h?r1=3.5&r2=3.6&ty=u Index: pecl/apc/apc_compile.h diff -u pecl/apc/apc_compile.h:3.5 pecl/apc/apc_compile.h:3.6 --- pecl/apc/apc_compile.h:3.5 Sat Sep 11 22:56:58 2004 +++ pecl/apc/apc_compile.h Sun Sep 12 10:31:44 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.h,v 3.5 2004/09/12 02:56:58 rasmus Exp $ */ +/* $Id: apc_compile.h,v 3.6 2004/09/12 14:31:44 rasmus Exp $ */ #ifndef APC_COMPILE_H #define APC_COMPILE_H @@ -56,7 +56,7 @@ extern zend_class_entry* apc_copy_class_entry(zend_class_entry* dst, zend_class_entry* src, apc_malloc_t allocate, apc_free_t deallocate); extern apc_function_t* apc_copy_new_functions(int old_count, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); extern apc_class_t* apc_copy_new_classes(zend_op_array* op_array, int old_count, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); -extern zval* apc_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); +extern zval* apc_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC); /* * Deallocation functions corresponding to the copy functions above. http://cvs.php.net/diff.php/pecl/apc/php_apc.c?r1=3.36&r2=3.37&ty=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.36 pecl/apc/php_apc.c:3.37 --- pecl/apc/php_apc.c:3.36 Sun Sep 12 09:20:56 2004 +++ pecl/apc/php_apc.c Sun Sep 12 10:31:44 2004 @@ -2,19 +2,20 @@ +----------------------------------------------------------------------+ | Copyright (c) 2002 by Community Connect Inc. All rights reserved. | +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | + | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | - | http://www.php.net/license/3_0.txt. | + | http://www.php.net/license/3_0.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 | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | + | Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: php_apc.c,v 3.36 2004/09/12 13:20:56 rasmus Exp $ */ +/* $Id: php_apc.c,v 3.37 2004/09/12 14:31:44 rasmus Exp $ */ #ifdef PHP_WIN32 /* XXX lame hack, for some reason, the ini entries are all messed @@ -49,6 +50,8 @@ PHP_FUNCTION(apc_sma_info); PHP_FUNCTION(apc_store); PHP_FUNCTION(apc_fetch); +PHP_FUNCTION(apc_define_constants); +PHP_FUNCTION(apc_load_constants); /* }}} */ /* {{{ ZEND_DECLARE_MODULE_GLOBALS(apc) */ @@ -122,7 +125,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.36 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.37 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); DISPLAY_INI_ENTRIES(); php_info_print_table_end(); @@ -335,29 +338,18 @@ } /* }}} */ -/* {{{ proto int apc_store(string key, zval var [, ttl ]) - */ -PHP_FUNCTION(apc_store) { - zval *val; - char *strkey; - int strkey_len; - apc_cache_entry_t *entry; +static int _apc_store(const char *strkey, const zval *val, const unsigned int ttl TSRMLS_DC) { + apc_cache_entry_t *entry; apc_cache_key_t key; - long ttl = 0L; time_t t; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|l", &strkey, &strkey_len, &val, &ttl) == FAILURE) { - return; - } - - - if (!(entry = apc_cache_make_user_entry(strkey, val, (unsigned int)ttl))) { - RETURN_FALSE; + if (!(entry = apc_cache_make_user_entry(strkey, val, ttl))) { + return 0; } if (!apc_cache_make_user_key(&key, strkey TSRMLS_CC)) { apc_cache_free_entry(entry); - RETURN_FALSE; + return 1; } #if HAVE_APACHE @@ -371,10 +363,28 @@ if (!apc_cache_user_insert(APCG(user_cache), key, entry, t)) { apc_cache_free_user_key(&key); apc_cache_free_entry(entry); - RETURN_FALSE; + return 0; } - RETURN_TRUE; + return 1; +} + +/* {{{ proto int apc_store(string key, zval var [, ttl ]) + */ +PHP_FUNCTION(apc_store) { + zval *val; + char *strkey; + int strkey_len; + long ttl = 0L; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz|l", &strkey, &strkey_len, &val, &ttl) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + + if(_apc_store(strkey, val, (unsigned int)ttl TSRMLS_CC)) RETURN_TRUE; + RETURN_FALSE; } /* }}} */ @@ -390,6 +400,8 @@ return; } + if(!strkey_len) RETURN_FALSE; + #if HAVE_APACHE /* Save a syscall here under Apache. This should actually be a SAPI call instead * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ @@ -423,6 +435,91 @@ return; } + if(!strkey_len) RETURN_FALSE; + + if(apc_cache_user_delete(APCG(user_cache), strkey, strkey_len)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +static void _apc_define_constants(zval *constants, zend_bool case_sensitive) { + char *const_key; + int const_key_len; + zval **entry; + HashPosition pos; + + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(constants), &pos); + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(constants), (void**)&entry, &pos) == SUCCESS) { + zend_constant c; + int key_type; + ulong num_key; + + key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(constants), &const_key, &const_key_len, &num_key, 0, &pos); + if(key_type != HASH_KEY_IS_STRING) { + continue; + } + switch(Z_TYPE_PP(entry)) { + case IS_LONG: + case IS_DOUBLE: + case IS_STRING: + case IS_BOOL: + case IS_RESOURCE: + case IS_NULL: + break; + default: + continue; + } + c.value = **entry; + zval_copy_ctor(&c.value); + c.flags = case_sensitive; + c.name = zend_strndup(const_key, const_key_len); + c.name_len = const_key_len; + zend_register_constant(&c TSRMLS_CC); + + zend_hash_move_forward_ex(Z_ARRVAL_P(constants), &pos); + } +} + +/* {{{ proto mixed apc_define_constants(string key, array constants [,bool case-sensitive]) + */ +PHP_FUNCTION(apc_define_constants) { + char *strkey; + int strkey_len; + ulong num_key; + zval *constants = NULL; + zend_bool case_sensitive = 1; + int argc = ZEND_NUM_ARGS(); + + if (zend_parse_parameters(argc TSRMLS_CC, "sa|b", &strkey, &strkey_len, &constants, &case_sensitive) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + + _apc_define_constants(constants, case_sensitive); + + if(_apc_store(strkey, constants, 0 TSRMLS_CC)) RETURN_TRUE; + RETURN_FALSE; +} /* }}} */ + +/* {{{ proto mixed apc_load_constants(string key [, bool case-sensitive]) + */ +PHP_FUNCTION(apc_load_constants) { + char *strkey; + int strkey_len; + apc_cache_entry_t* entry; + time_t t; + zend_bool case_sensitive = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &strkey, &strkey_len, &case_sensitive) == FAILURE) { + return; + } + + if(!strkey_len) RETURN_FALSE; + #if HAVE_APACHE /* Save a syscall here under Apache. This should actually be a SAPI call instead * but we don't have that yet. Once that is introduced in PHP this can be cleaned up -Rasmus */ @@ -431,7 +528,11 @@ t = time(0); #endif - if(apc_cache_user_delete(APCG(user_cache), strkey, strkey_len)) { + entry = apc_cache_user_find(APCG(user_cache), strkey, strkey_len, t); + + if(entry) { + apc_stack_push(APCG(user_cache_stack), entry); + _apc_define_constants(entry->data.user.val, case_sensitive); RETURN_TRUE; } else { RETURN_FALSE; @@ -447,6 +548,8 @@ PHP_FE(apc_store, NULL) PHP_FE(apc_fetch, NULL) PHP_FE(apc_delete, NULL) + PHP_FE(apc_define_constants, NULL) + PHP_FE(apc_load_constants, NULL) {NULL, NULL, NULL} }; /* }}} */