cvs: pecl /apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_fcntl.c apc_fcntl.h apc_globals.h apc_main.c apc_main.h apc_php.h apc_sma.c
apc_sma.h php_apc.c

From: Date: Sun, 12 Sep 2004 02:56:58 +0000
Subject: cvs: pecl /apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_fcntl.c apc_fcntl.h apc_globals.h apc_main.c apc_main.h apc_php.h apc_sma.c
apc_sma.h php_apc.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-1819@lists.php.net to get a copy of this message
rasmus Sat Sep 11 22:56:58 2004 EDT Modified files: /pecl/apc apc_cache.c apc_cache.h apc_compile.c apc_compile.h apc_fcntl.c apc_fcntl.h apc_globals.h apc_main.c apc_main.h apc_php.h apc_sma.c apc_sma.h php_apc.c Log: Major patch that likely breaks everything. This adds user-level content caching via apc_store(), apc_fetch() and apc_delete(). Full docs are coming. Tagged the tree with BEFORE_CONTENT_PATCH to back this one back out if necessary.

http://cvs.php.net/diff.php/pecl/apc/apc_cache.c?r1=3.66&r2=3.67&ty=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.66 pecl/apc/apc_cache.c:3.67 --- pecl/apc/apc_cache.c:3.66 Wed Sep 8 14:27:30 2004 +++ pecl/apc/apc_cache.c Sat Sep 11 22:56:58 2004 @@ -11,10 +11,11 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | + | Rasmus Lerdorf <rasmus@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.c,v 3.66 2004/09/08 18:27:30 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.67 2004/09/12 02:56:58 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -72,7 +73,36 @@ /* {{{ hash */ static unsigned int hash(apc_cache_key_t key) { - return key.device + key.inode; + return key.data.file.device + key.data.file.inode; +} +/* }}} */ + +/* {{{ string_nhash_8 */ +static unsigned int string_nhash_8(const char *s, size_t len) +{ + register const unsigned int *iv = (const unsigned int *)s; + register unsigned int h = 0; + register unsigned int n; + + if (len > 3) { + if (len & 3) { + h = *(unsigned int *)(s + len - 4); + } + len /= 4; + for (n = 0; n < len; n++) { + h+= iv[n]; + h = (h << 7) | (h >> (32 - 7)); + } + } else { + if (len > 1) { + h += s[1]; + if (len == 3) h += s[2]; + } + h += s[0]; + } + h ^= (h >> 13); + h ^= (h >> 7); + return h; } /* }}} */ @@ -142,11 +172,19 @@ if ((*slot)->value->ref_count <= 0 || gc_sec > cache->gc_ttl) { slot_t* dead = *slot; - if (dead->value->ref_count > 0) - apc_log(APC_WARNING, "GC cache entry '%s' (dev=%d ino=%d) " - "was on gc-list for %d seconds", dead->value->filename, - dead->key.device, dead->key.inode, gc_sec); - + if (dead->value->ref_count > 0) { + switch(dead->value->type) { + case APC_CACHE_ENTRY_FILE: + apc_log(APC_WARNING, "GC cache entry '%s' (dev=%d ino=%d) " + "was on gc-list for %d seconds", dead->value->data.file.filename, + dead->key.data.file.device, dead->key.data.file.inode, gc_sec); + break; + case APC_CACHE_ENTRY_USER: + apc_log(APC_WARNING, "GC cache entry '%s' " + "was on gc-list for %d seconds", dead->value->data.user.info, gc_sec); + break; + } + } *slot = dead->next; free_slot(dead); } @@ -165,17 +203,17 @@ enum { BIG_VALUE = 1000 }; - entry->op_array->refcount[0] = BIG_VALUE; - if (entry->functions) { + entry->data.file.op_array->refcount[0] = BIG_VALUE; + if (entry->data.file.functions) { int i; - apc_function_t* fns = entry->functions; + apc_function_t* fns = entry->data.file.functions; for (i=0; fns[i].function != NULL; i++) { fns[i].function->op_array.refcount[0] = BIG_VALUE; } } - if (entry->classes) { + if (entry->data.file.classes) { int i; - apc_class_t* classes = entry->classes; + apc_class_t* classes = entry->data.file.classes; for (i=0; classes[i].class_entry != NULL; i++) { classes[i].class_entry->refcount[0] = BIG_VALUE; } @@ -285,13 +323,16 @@ return 0; } + printf("apc_cache_insert called for key at 0x%lx and value at 0x%lx\n",key,value); + LOCK(cache); process_pending_removals(cache); slot = &cache->slots[hash(key) % cache->num_slots]; while (*slot) { - if (key_equals((*slot)->key, key)) { + if (key_equals((*slot)->key.data.file, key.data.file)) { + /* If existing slot for the same device+inode is older, remove it and insert the new version */ if ((*slot)->key.mtime < key.mtime) { remove_slot(cache, slot); break; @@ -315,6 +356,53 @@ } /* }}} */ +/* {{{ apc_cache_user_insert */ +int apc_cache_user_insert(apc_cache_t* cache, apc_cache_key_t key, apc_cache_entry_t* value, time_t t) +{ + slot_t** slot; + int ilen; + + if (!value) { + return 0; + } + + LOCK(cache); + process_pending_removals(cache); + + ilen = strlen(key.data.user.identifier); + slot = &cache->slots[string_nhash_8(key.data.user.identifier, ilen) % cache->num_slots]; + + while (*slot) { + if (!strncmp((*slot)->key.data.user.identifier, key.data.user.identifier, ilen)) { + /* If a slot with the same identifier already exists, remove it */ + remove_slot(cache, slot); + break; + } else + /* + * This is a bit nasty. The idea here is to do runtime cleanup of the linked list of + * slot entries so we don't always have to skip past a bunch of stale entries. We check + * for staleness here and get rid of them by first checking to see if the cache has a global + * access ttl on it and removing entries that haven't been accessed for ttl seconds and secondly + * we see if the entry has a hard ttl on it and remove it if it has been around longer than its ttl + */ + if((cache->ttl && (*slot)->access_time < (t - cache->ttl)) || + ((*slot)->value->data.user.ttl && ((*slot)->creation_time + (*slot)->value->data.user.ttl) < t)) { + remove_slot(cache, slot); + continue; + } + slot = &(*slot)->next; + } + + if ((*slot = make_slot(key, value, *slot, t)) == NULL) { + UNLOCK(cache); + return 0; + } + + UNLOCK(cache); + return 1; +} +/* }}} */ + /* {{{ apc_cache_find */ apc_cache_entry_t* apc_cache_find(apc_cache_t* cache, apc_cache_key_t key, time_t t) { @@ -325,7 +413,7 @@ slot = &cache->slots[hash(key) % cache->num_slots]; while (*slot) { - if (key_equals((*slot)->key, key)) { + if (key_equals((*slot)->key.data.file, key.data.file)) { if ((*slot)->key.mtime < key.mtime) { remove_slot(cache, slot); break; @@ -338,6 +426,7 @@ cache->header->num_hits++; UNLOCK(cache); + printf("apc_cache_find: found entry at 0x%lx\n",(*slot)->value); return (*slot)->value; } slot = &(*slot)->next; @@ -349,6 +438,63 @@ } /* }}} */ +/* {{{ apc_cache_user_find */ +apc_cache_entry_t* apc_cache_user_find(apc_cache_t* cache, char *strkey, int keylen, time_t t) +{ + slot_t** slot; + + LOCK(cache); + + slot = &cache->slots[string_nhash_8(strkey, keylen) % cache->num_slots]; + + while (*slot) { + if (!strncmp((*slot)->key.data.user.identifier, strkey, keylen)) { + /* Check to make sure this entry isn't expired by a hard TTL */ + if((*slot)->value->data.user.ttl && ((*slot)->creation_time + (*slot)->value->data.user.ttl) < t) { + remove_slot(cache, slot); + break; + } + /* Otherwise we are fine, increase counters and return the cache entry */ + (*slot)->num_hits++; + (*slot)->value->ref_count++; + (*slot)->access_time = t; + + cache->header->num_hits++; + UNLOCK(cache); + return (*slot)->value; + } + slot = &(*slot)->next; + } + + cache->header->num_misses++; + UNLOCK(cache); + return NULL; +} +/* }}} */ + +/* {{{ apc_cache_user_delete */ +int apc_cache_user_delete(apc_cache_t* cache, char *strkey, int keylen) +{ + slot_t** slot; + + LOCK(cache); + + slot = &cache->slots[string_nhash_8(strkey, keylen) % cache->num_slots]; + + while (*slot) { + if (!strncmp((*slot)->key.data.user.identifier, strkey, keylen)) { + remove_slot(cache, slot); + UNLOCK(cache); + return 1; + } + slot = &(*slot)->next; + } + + UNLOCK(cache); + return 0; +} +/* }}} */ + /* {{{ apc_cache_release */ void apc_cache_release(apc_cache_t* cache, apc_cache_entry_t* entry) { @@ -358,8 +504,8 @@ } /* }}} */ -/* {{{ apc_cache_make_key */ -int apc_cache_make_key(apc_cache_key_t* key, +/* {{{ apc_cache_make_file_key */ +int apc_cache_make_file_key(apc_cache_key_t* key, const char* filename, const char* include_path TSRMLS_DC) @@ -381,15 +527,39 @@ return 0; } - key->device = buf.st_dev; - key->inode = buf.st_ino; + key->data.file.device = buf.st_dev; + key->data.file.inode = buf.st_ino; key->mtime = (buf.st_ctime > buf.st_mtime) ? buf.st_ctime : buf.st_mtime; return 1; } /* }}} */ -/* {{{ apc_cache_make_entry */ -apc_cache_entry_t* apc_cache_make_entry(const char* filename, +/* {{{ apc_cache_make_user_key */ +int apc_cache_make_user_key(apc_cache_key_t* key, const char* identifier, time_t t) +{ + assert(key != NULL); + + if (!identifier) + return 0; + + key->data.user.identifier = apc_xstrdup(identifier, apc_sma_malloc); + key->mtime = t; + return 1; +} +/* }}} */ + +/* {{{ apc_cache_free_user_key */ +int apc_cache_free_user_key(apc_cache_key_t* key) +{ + assert(key != NULL); + + apc_sma_free(key->data.user.identifier); + return 1; +} +/* }}} */ + +/* {{{ apc_cache_make_file_entry */ +apc_cache_entry_t* apc_cache_make_file_entry(const char* filename, zend_op_array* op_array, apc_function_t* functions, apc_class_t* classes) @@ -398,14 +568,44 @@ entry = (apc_cache_entry_t*) apc_sma_malloc(sizeof(apc_cache_entry_t)); if (!entry) return NULL; - entry->filename = apc_xstrdup(filename, apc_sma_malloc); - if(!entry->filename) { + printf("Made new file entry at 0x%lx\n",entry); + + entry->data.file.filename = apc_xstrdup(filename, apc_sma_malloc); + if(!entry->data.file.filename) { apc_sma_free(entry); return NULL; } - entry->op_array = op_array; - entry->functions = functions; - entry->classes = classes; + entry->data.file.op_array = op_array; + entry->data.file.functions = functions; + entry->data.file.classes = classes; + entry->type = APC_CACHE_ENTRY_FILE; + entry->ref_count = 0; + return entry; +} +/* }}} */ + +/* {{{ 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* entry; + + entry = (apc_cache_entry_t*) apc_sma_malloc(sizeof(apc_cache_entry_t)); + if (!entry) return NULL; + printf("Made new user entry at 0x%lx\n",entry); + + entry->data.user.info = apc_xstrdup(info, apc_sma_malloc); + if(!entry->data.user.info) { + apc_sma_free(entry); + return NULL; + } + entry->data.user.val = apc_copy_zval(NULL, val, apc_sma_malloc, apc_sma_free); + if(!entry->data.user.val) { + apc_sma_free(entry->data.user.info); + apc_sma_free(entry); + return NULL; + } + entry->data.user.ttl = ttl; + entry->type = APC_CACHE_ENTRY_USER; entry->ref_count = 0; return entry; } @@ -416,10 +616,18 @@ { if (entry != NULL) { assert(entry->ref_count == 0); - apc_sma_free(entry->filename); - apc_free_op_array(entry->op_array, apc_sma_free); - apc_free_functions(entry->functions, apc_sma_free); - apc_free_classes(entry->classes, apc_sma_free); + switch(entry->type) { + case APC_CACHE_ENTRY_FILE: + apc_sma_free(entry->data.file.filename); + apc_free_op_array(entry->data.file.op_array, apc_sma_free); + apc_free_functions(entry->data.file.functions, apc_sma_free); + apc_free_classes(entry->data.file.classes, apc_sma_free); + break; + case APC_CACHE_ENTRY_USER: + apc_sma_free(entry->data.user.info); + apc_free_zval(entry->data.user.val, apc_sma_free); + break; + } apc_sma_free(entry); } } @@ -451,9 +659,16 @@ apc_cache_link_t* link = (apc_cache_link_t*) apc_emalloc(sizeof(apc_cache_link_t)); - link->filename = apc_xstrdup(p->value->filename, apc_emalloc); - link->device = p->key.device; - link->inode = p->key.inode; + if(p->value->type == APC_CACHE_ENTRY_FILE) { + link->data.file.filename = apc_xstrdup(p->value->data.file.filename, apc_emalloc); + link->data.file.device = p->key.data.file.device; + link->data.file.inode = p->key.data.file.inode; + link->type = APC_CACHE_ENTRY_FILE; + } else if(p->value->type == APC_CACHE_ENTRY_USER) { + link->data.user.info = apc_xstrdup(p->value->data.user.info, apc_emalloc); + link->data.user.ttl = p->value->data.user.ttl; + link->type = APC_CACHE_ENTRY_USER; + } link->num_hits = p->num_hits; link->mtime = p->key.mtime; link->creation_time = p->creation_time; @@ -470,9 +685,16 @@ apc_cache_link_t* link = (apc_cache_link_t*) apc_emalloc(sizeof(apc_cache_link_t)); - link->filename = apc_xstrdup(p->value->filename, apc_emalloc); - link->device = p->key.device; - link->inode = p->key.inode; + if(p->value->type == APC_CACHE_ENTRY_FILE) { + link->data.file.filename = apc_xstrdup(p->value->data.file.filename, apc_emalloc); + link->data.file.device = p->key.data.file.device; + link->data.file.inode = p->key.data.file.inode; + link->type = APC_CACHE_ENTRY_FILE; + } else if(p->value->type == APC_CACHE_ENTRY_USER) { + link->data.user.info = apc_xstrdup(p->value->data.user.info, apc_emalloc); + link->data.user.ttl = p->value->data.user.ttl; + link->type = APC_CACHE_ENTRY_USER; + } link->num_hits = p->num_hits; link->mtime = p->key.mtime; link->creation_time = p->creation_time; @@ -495,7 +717,8 @@ while (p != NULL) { apc_cache_link_t* q = p; p = p->next; - apc_efree(q->filename); + if(q->type == APC_CACHE_ENTRY_FILE) apc_efree(q->data.file.filename); + else if(q->type == APC_CACHE_ENTRY_USER) apc_efree(q->data.user.info); apc_efree(q); } apc_efree(info); http://cvs.php.net/diff.php/pecl/apc/apc_cache.h?r1=3.18&r2=3.19&ty=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.18 pecl/apc/apc_cache.h:3.19 --- pecl/apc/apc_cache.h:3.18 Wed Sep 8 14:27:30 2004 +++ pecl/apc/apc_cache.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.h,v 3.18 2004/09/08 18:27:30 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.19 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -27,26 +27,50 @@ #include "apc.h" #include "apc_compile.h" +#define APC_CACHE_ENTRY_FILE 1 +#define APC_CACHE_ENTRY_USER 2 + #define T apc_cache_t* typedef struct apc_cache_t apc_cache_t; /* opaque cache type */ +typedef union _apc_cache_key_data_t { + struct { + int device; /* the filesystem device */ + int inode; /* the filesystem inode */ + } file; + struct { + char *identifier; + } user; +} apc_cache_key_data_t; + /* {{{ struct definition: apc_cache_key_t */ typedef struct apc_cache_key_t apc_cache_key_t; struct apc_cache_key_t { - int device; /* the filesystem device */ - int inode; /* the filesystem inode */ - int mtime; /* the mtime of this cached file */ + apc_cache_key_data_t data; + int mtime; /* the mtime of this cached entry */ }; /* }}} */ +typedef union _apc_cache_entry_value_t { + struct { + char *filename; /* absolute path to source file */ + zend_op_array* op_array; /* op_array allocated in shared memory */ + apc_function_t* functions; /* array of apc_function_t's */ + apc_class_t* classes; /* array of apc_class_t's */ + } file; + struct { + char *info; + zval *val; + unsigned int ttl; + } user; +} apc_cache_entry_value_t; + /* {{{ struct definition: apc_cache_entry_t */ typedef struct apc_cache_entry_t apc_cache_entry_t; struct apc_cache_entry_t { - char* filename; /* absolute path to source file */ - zend_op_array* op_array; /* op_array allocated in shared memory */ - apc_function_t* functions; /* array of apc_function_t's */ - apc_class_t* classes; /* array of apc_class_t's */ - int ref_count; /* concurrently executing processes */ + apc_cache_entry_value_t data; + unsigned char type; + int ref_count; }; /* }}} */ @@ -91,22 +115,37 @@ * returned, the caller must free the cache entry by calling * apc_cache_free_entry (see below). * - * key is the value created by apc_cache_make_key. + * key is the value created by apc_cache_make_file_key for file keys. * * value is a cache entry returned by apc_cache_make_entry (see below). */ extern int apc_cache_insert(T cache, apc_cache_key_t key, apc_cache_entry_t* value, time_t t); +extern int apc_cache_user_insert(T cache, apc_cache_key_t key, + apc_cache_entry_t* value, time_t t); + /* * apc_cache_find searches for a cache entry by filename, and returns a * pointer to the entry if found, NULL otherwise. * - * key is a value created by apc_cache_make_key. + * key is a value created by apc_cache_make_file_key for file keys. */ extern apc_cache_entry_t* apc_cache_find(T cache, apc_cache_key_t key, time_t t); /* + * apc_cache_user_find searches for a cache entry by its hashed identifier, + * and returns a pointer to the entry if found, NULL otherwise. + * + */ +extern apc_cache_entry_t* apc_cache_user_find(T cache, char* strkey, int keylen, time_t t); + +/* + * apc_cache_user_delete finds an entry in the user cache and deletes it. + */ +extern int apc_cache_user_delete(apc_cache_t* cache, char *strkey, int keylen); + +/* * apc_cache_release decrements the reference count associated with a cache * entry. Calling apc_cache_find automatically increments the reference count, * and this function must be called post-execution to return the count to its @@ -118,7 +157,7 @@ extern void apc_cache_release(T cache, apc_cache_entry_t* entry); /* - * apc_cache_make_key creates a key object given a relative or absolute + * apc_cache_make_file_key creates a key object given a relative or absolute * filename and an optional list of auxillary paths to search. include_path is * searched if the filename cannot be found relative to the current working * directory. @@ -129,19 +168,24 @@ * * include_path is a colon-separated list of directories to search. */ -extern int apc_cache_make_key(apc_cache_key_t* key, - const char* filename, - const char* include_path - TSRMLS_DC); +extern int apc_cache_make_file_key(apc_cache_key_t* key, + const char* filename, + const char* include_path + TSRMLS_DC); /* - * apc_cache_make_entry creates an apc_cache_entry_t object given a filename + * apc_cache_make_file_entry creates an apc_cache_entry_t object given a filename * and the compilation results returned by the PHP compiler. */ -extern apc_cache_entry_t* apc_cache_make_entry(const char* filename, - zend_op_array* op_array, - apc_function_t* functions, - apc_class_t* classes); +extern apc_cache_entry_t* apc_cache_make_file_entry(const char* filename, + zend_op_array* op_array, + apc_function_t* functions, + apc_class_t* classes); +/* + * 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); /* * Frees all memory associated with an object returned by apc_cache_make_entry @@ -149,13 +193,25 @@ */ extern void apc_cache_free_entry(apc_cache_entry_t* entry); +/* {{{ struct definition: apc_cache_link_data_t */ +typedef union _apc_cache_link_data_t { + struct { + char *filename; + int device; + int inode; + } file; + struct { + char *info; + unsigned int ttl; + } user; +} apc_cache_link_data_t; +/* }}} */ /* {{{ struct definition: apc_cache_link_t */ typedef struct apc_cache_link_t apc_cache_link_t; struct apc_cache_link_t { - char* filename; - int device; - int inode; + apc_cache_link_data_t data; + unsigned char type; int num_hits; time_t mtime; time_t creation_time; http://cvs.php.net/diff.php/pecl/apc/apc_compile.c?r1=3.11&r2=3.12&ty=u Index: pecl/apc/apc_compile.c diff -u pecl/apc/apc_compile.c:3.11 pecl/apc/apc_compile.c:3.12 --- pecl/apc/apc_compile.c:3.11 Tue Sep 7 00:56:25 2004 +++ pecl/apc/apc_compile.c Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.c,v 3.11 2004/09/07 04:56:25 rasmus Exp $ */ +/* $Id: apc_compile.c,v 3.12 2004/09/12 02:56:58 rasmus Exp $ */ #include "apc_compile.h" #include "apc_globals.h" @@ -262,7 +262,9 @@ dst ->op_type == IS_UNUSED); if (src->op_type == IS_CONST) { - if(!my_copy_zval(&dst->u.constant, &src->u.constant, allocate, deallocate)) return NULL; + if(!my_copy_zval(&dst->u.constant, &src->u.constant, allocate, deallocate)) { + return NULL; + } } return dst; @@ -574,6 +576,25 @@ } /* }}} */ +/* {{{ apc_copy_zval */ +zval* apc_copy_zval(zval* dst, zval* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) +{ + int local_dst_alloc = 0; + assert(src != NULL); + + if (!dst) { + CHECK(dst = (zval*) allocate(sizeof(zval))); + local_dst_alloc = 1; + } + + if(!my_copy_zval(dst, src, allocate, deallocate)) { + if(local_dst_alloc) deallocate(dst); + return NULL; + } + return dst; +} +/* }}} */ + /* {{{ apc_copy_op_array */ zend_op_array* apc_copy_op_array(zend_op_array* dst, zend_op_array* src, apc_malloc_t allocate, apc_free_t deallocate TSRMLS_DC) { @@ -1100,6 +1121,16 @@ } deallocate(src); } +} +/* }}} */ + +/* {{{ apc_free_zval */ +void apc_free_zval(zval* src, apc_free_t deallocate) +{ + if (src != NULL) { + my_destroy_zval(src, deallocate); + deallocate(src); + } } /* }}} */ http://cvs.php.net/diff.php/pecl/apc/apc_compile.h?r1=3.4&r2=3.5&ty=u Index: pecl/apc/apc_compile.h diff -u pecl/apc/apc_compile.h:3.4 pecl/apc/apc_compile.h:3.5 --- pecl/apc/apc_compile.h:3.4 Thu Sep 2 19:08:31 2004 +++ pecl/apc/apc_compile.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_compile.h,v 3.4 2004/09/02 23:08:31 rasmus Exp $ */ +/* $Id: apc_compile.h,v 3.5 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_COMPILE_H #define APC_COMPILE_H @@ -56,6 +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); /* * Deallocation functions corresponding to the copy functions above. @@ -64,6 +65,7 @@ extern void apc_free_op_array(zend_op_array* src, apc_free_t deallocate); extern void apc_free_functions(apc_function_t* src, apc_free_t deallocate); extern void apc_free_classes(apc_class_t* src, apc_free_t deallocate); +extern void apc_free_zval(zval* src, apc_free_t deallocate); /* * These "copy-for-execution" functions must be called after retrieving an http://cvs.php.net/diff.php/pecl/apc/apc_fcntl.c?r1=3.16&r2=3.17&ty=u Index: pecl/apc/apc_fcntl.c diff -u pecl/apc/apc_fcntl.c:3.16 pecl/apc/apc_fcntl.c:3.17 --- pecl/apc/apc_fcntl.c:3.16 Sat Jun 28 22:51:39 2003 +++ pecl/apc/apc_fcntl.c Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_fcntl.c,v 3.16 2003/06/29 02:51:39 gschlossnagle Exp $ */ +/* $Id: apc_fcntl.c,v 3.17 2004/09/12 02:56:58 rasmus Exp $ */ #include "apc_fcntl.h" #include "apc.h" http://cvs.php.net/diff.php/pecl/apc/apc_fcntl.h?r1=3.9&r2=3.10&ty=u Index: pecl/apc/apc_fcntl.h diff -u pecl/apc/apc_fcntl.h:3.9 pecl/apc/apc_fcntl.h:3.10 --- pecl/apc/apc_fcntl.h:3.9 Sat Jun 28 22:51:39 2003 +++ pecl/apc/apc_fcntl.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_fcntl.h,v 3.9 2003/06/29 02:51:39 gschlossnagle Exp $ */ +/* $Id: apc_fcntl.h,v 3.10 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_FCNTL_H #define APC_FCNTL_H http://cvs.php.net/diff.php/pecl/apc/apc_globals.h?r1=3.8&r2=3.9&ty=u Index: pecl/apc/apc_globals.h diff -u pecl/apc/apc_globals.h:3.8 pecl/apc/apc_globals.h:3.9 --- pecl/apc/apc_globals.h:3.8 Thu Aug 12 13:35:00 2004 +++ pecl/apc/apc_globals.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_globals.h,v 3.8 2004/08/12 17:35:00 rasmus Exp $ */ +/* $Id: apc_globals.h,v 3.9 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_GLOBALS_H #define APC_GLOBALS_H @@ -30,8 +30,10 @@ int shm_size; /* size of each shared memory segment (in MB) */ int optimization; /* optimizer level (higher = more aggressive) */ int num_files_hint; /* parameter to apc_cache_create */ + int user_entries_hint; int gc_ttl; /* parameter to apc_cache_create */ int ttl; /* parameter to apc_cache_create */ + int user_ttl; #if APC_MMAP char *mmap_file_mask; /* mktemp-style file-mask to pass to mmap */ #endif @@ -40,7 +42,9 @@ /* module variables */ int initialized; /* true if module was initialized */ apc_cache_t* cache; /* the global compiler cache */ + apc_cache_t* user_cache; /* the global user content cache */ apc_stack_t* cache_stack; /* the stack of cached executable code */ + apc_stack_t* user_cache_stack; /* the stack of cached user entries */ void* compiled_filters; /* compiled filters */ int cache_by_default; /* true if files should be cached unless filtered out */ /* false if files should only be cached if filtered in */ http://cvs.php.net/diff.php/pecl/apc/apc_main.c?r1=3.19&r2=3.20&ty=u Index: pecl/apc/apc_main.c diff -u pecl/apc/apc_main.c:3.19 pecl/apc/apc_main.c:3.20 --- pecl/apc/apc_main.c:3.19 Wed Sep 8 14:27:30 2004 +++ pecl/apc/apc_main.c Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_main.c,v 3.19 2004/09/08 18:27:30 rasmus Exp $ */ +/* $Id: apc_main.c,v 3.20 2004/09/12 02:56:58 rasmus Exp $ */ #include "apc_php.h" #include "apc_main.h" @@ -105,19 +105,19 @@ cache_entry = (apc_cache_entry_t*) apc_stack_top(APCG(cache_stack)); assert(cache_entry != NULL); - if (cache_entry->functions) { - for (i = 0; cache_entry->functions[i].function != NULL; i++) { - install_function(cache_entry->functions[i] TSRMLS_CC); + if (cache_entry->data.file.functions) { + for (i = 0; cache_entry->data.file.functions[i].function != NULL; i++) { + install_function(cache_entry->data.file.functions[i] TSRMLS_CC); } } - if (cache_entry->classes) { - for (i = 0; cache_entry->classes[i].class_entry != NULL; i++) { - install_class(cache_entry->classes[i] TSRMLS_CC); + if (cache_entry->data.file.classes) { + for (i = 0; cache_entry->data.file.classes[i].class_entry != NULL; i++) { + install_class(cache_entry->data.file.classes[i] TSRMLS_CC); } } - return apc_copy_op_array_for_execution(cache_entry->op_array); + return apc_copy_op_array_for_execution(cache_entry->data.file.op_array); } /* }}} */ @@ -154,7 +154,7 @@ #endif /* try to create a cache key; if we fail, give up on caching */ - if (!apc_cache_make_key(&key, h->filename, PG(include_path) TSRMLS_CC)) { + if (!apc_cache_make_file_key(&key, h->filename, PG(include_path) TSRMLS_CC)) { return old_compile_file(h, type TSRMLS_CC); } @@ -162,7 +162,7 @@ cache_entry = apc_cache_find(APCG(cache), key, t); if (cache_entry != NULL) { if (h->opened_path == NULL) { - h->opened_path = estrdup(cache_entry->filename); + h->opened_path = estrdup(cache_entry->data.file.filename); } zend_llist_add_element(&CG(open_files), h); /* XXX kludge */ apc_stack_push(APCG(cache_stack), cache_entry); @@ -203,13 +203,13 @@ return op_array; } - if(!(cache_entry = apc_cache_make_entry(h->opened_path, alloc_op_array, alloc_functions, alloc_classes))) { + if(!(cache_entry = apc_cache_make_file_entry(h->opened_path, alloc_op_array, alloc_functions, alloc_classes))) { apc_free_op_array(alloc_op_array, apc_sma_free); apc_free_functions(alloc_functions, apc_sma_free); apc_free_classes(alloc_classes, apc_sma_free); apc_cache_expunge(APCG(cache),t); HANDLE_UNBLOCK_INTERRUPTIONS(); - apc_log(APC_WARNING, "(apc_cache_make_entry) unable to cache '%s': insufficient " "shared memory available", h->opened_path); + apc_log(APC_WARNING, "(apc_cache_make_file_entry) unable to cache '%s': insufficient " "shared memory available", h->opened_path); return op_array; } HANDLE_UNBLOCK_INTERRUPTIONS(); @@ -266,6 +266,8 @@ apc_sma_init(APCG(shm_segments), APCG(shm_size)*1024*1024, NULL); #endif APCG(cache) = apc_cache_create(APCG(num_files_hint), APCG(gc_ttl), APCG(ttl)); + APCG(user_cache) = apc_cache_create(APCG(user_entries_hint), APCG(gc_ttl), APCG(user_ttl)); + APCG(user_cache_stack) = apc_stack_create(0); APCG(cache_stack) = apc_stack_create(0); APCG(compiled_filters) = apc_regex_compile_array(APCG(filters)); @@ -276,11 +278,6 @@ /* override execution */ old_execute = zend_execute; zend_execute = my_execute; - -#if 0 - /* startup output is not good for stuff like fastcgi */ - apc_log(APC_NOTICE, "APC version %s -- startup complete", apc_version()); -#endif APCG(initialized) = 1; return 0; @@ -307,18 +304,18 @@ while (apc_stack_size(APCG(cache_stack)) > 0) { int i; apc_cache_entry_t* cache_entry = (apc_cache_entry_t*) apc_stack_pop(APCG(cache_stack)); - if (cache_entry->functions) { - for (i = 0; cache_entry->functions[i].function != NULL; i++) { + if (cache_entry->data.file.functions) { + for (i = 0; cache_entry->data.file.functions[i].function != NULL; i++) { zend_hash_del(EG(function_table), - cache_entry->functions[i].name, - cache_entry->functions[i].name_len+1); + cache_entry->data.file.functions[i].name, + cache_entry->data.file.functions[i].name_len+1); } } - if (cache_entry->classes) { - for (i = 0; cache_entry->classes[i].class_entry != NULL; i++) { + if (cache_entry->data.file.classes) { + for (i = 0; cache_entry->data.file.classes[i].class_entry != NULL; i++) { zend_hash_del(EG(class_table), - cache_entry->classes[i].name, - cache_entry->classes[i].name_len+1); + cache_entry->data.file.classes[i].name, + cache_entry->data.file.classes[i].name_len+1); } } apc_cache_free_entry(cache_entry); @@ -326,9 +323,11 @@ /* apc cleanup */ apc_stack_destroy(APCG(cache_stack)); + apc_stack_destroy(APCG(user_cache_stack)); apc_cache_destroy(APCG(cache)); + apc_cache_destroy(APCG(user_cache)); apc_sma_cleanup(); - + APCG(initialized) = 0; return 0; } @@ -341,6 +340,7 @@ { TSRMLS_FETCH(); apc_stack_clear(APCG(cache_stack)); + apc_stack_clear(APCG(user_cache_stack)); return 0; } @@ -364,13 +364,18 @@ (apc_cache_entry_t*) apc_stack_pop(APCG(cache_stack)); apc_cache_release(APCG(cache), cache_entry); } + while (apc_stack_size(APCG(user_cache_stack)) > 0) { + apc_cache_entry_t* cache_entry = + (apc_cache_entry_t*) apc_stack_pop(APCG(user_cache_stack)); + apc_cache_release(APCG(user_cache), cache_entry); + } } /* }}} */ /* {{{ apc_version */ const char* apc_version() { - return "2.0.5"; + return "2.1.0"; } /* }}} */ http://cvs.php.net/diff.php/pecl/apc/apc_main.h?r1=3.2&r2=3.3&ty=u Index: pecl/apc/apc_main.h diff -u pecl/apc/apc_main.h:3.2 pecl/apc/apc_main.h:3.3 --- pecl/apc/apc_main.h:3.2 Sat Jun 28 22:51:39 2003 +++ pecl/apc/apc_main.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_main.h,v 3.2 2003/06/29 02:51:39 gschlossnagle Exp $ */ +/* $Id: apc_main.h,v 3.3 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_MAIN_H #define APC_MAIN_H http://cvs.php.net/diff.php/pecl/apc/apc_php.h?r1=3.2&r2=3.3&ty=u Index: pecl/apc/apc_php.h diff -u pecl/apc/apc_php.h:3.2 pecl/apc/apc_php.h:3.3 --- pecl/apc/apc_php.h:3.2 Sat Jun 28 22:51:39 2003 +++ pecl/apc/apc_php.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_php.h,v 3.2 2003/06/29 02:51:39 gschlossnagle Exp $ */ +/* $Id: apc_php.h,v 3.3 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_PHP_H #define APC_PHP_H @@ -25,6 +25,7 @@ * all required headers are available. */ +#include "php_config.h" #include "php.h" #include "zend.h" #include "zend_API.h" http://cvs.php.net/diff.php/pecl/apc/apc_sma.c?r1=1.19&r2=1.20&ty=u Index: pecl/apc/apc_sma.c diff -u pecl/apc/apc_sma.c:1.19 pecl/apc/apc_sma.c:1.20 --- pecl/apc/apc_sma.c:1.19 Tue Sep 7 16:24:30 2004 +++ pecl/apc/apc_sma.c Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_sma.c,v 1.19 2004/09/07 20:24:30 rasmus Exp $ */ +/* $Id: apc_sma.c,v 1.20 2004/09/12 02:56:58 rasmus Exp $ */ #include "apc_sma.h" #include "apc.h" @@ -320,6 +320,30 @@ UNLOCK(sma_lock); return NULL; +} +/* }}} */ + +/* {{{ apc_sma_realloc */ +void* apc_sma_realloc(void *p, size_t n) +{ + apc_sma_free(p); + return apc_sma_malloc(n); +} +/* }}} */ + +/* {{{ apc_sma_strdup */ +void* apc_sma_strdup(const char* s) +{ + void* q; + int len; + + if(!s) return NULL; + + len = strlen(s)+1; + q = apc_sma_malloc(len); + if(!q) return NULL; + memcpy(q, s, len); + return q; } /* }}} */ http://cvs.php.net/diff.php/pecl/apc/apc_sma.h?r1=1.8&r2=1.9&ty=u Index: pecl/apc/apc_sma.h diff -u pecl/apc/apc_sma.h:1.8 pecl/apc/apc_sma.h:1.9 --- pecl/apc/apc_sma.h:1.8 Fri Aug 20 12:41:40 2004 +++ pecl/apc/apc_sma.h Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_sma.h,v 1.8 2004/08/20 16:41:40 rasmus Exp $ */ +/* $Id: apc_sma.h,v 1.9 2004/09/12 02:56:58 rasmus Exp $ */ #ifndef APC_SMA_H #define APC_SMA_H @@ -26,6 +26,8 @@ extern void apc_sma_init(int numseg, int segsize, char *mmap_file_mask); extern void apc_sma_cleanup(); extern void* apc_sma_malloc(size_t size); +extern void* apc_sma_realloc(void* p, size_t size); +extern void* apc_sma_strdup(const char *s); extern void apc_sma_free(void* p); /* {{{ struct definition: apc_sma_link_t */ http://cvs.php.net/diff.php/pecl/apc/php_apc.c?r1=3.33&r2=3.34&ty=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.33 pecl/apc/php_apc.c:3.34 --- pecl/apc/php_apc.c:3.33 Tue Sep 7 00:41:30 2004 +++ pecl/apc/php_apc.c Sat Sep 11 22:56:58 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apc.c,v 3.33 2004/09/07 04:41:30 rasmus Exp $ */ +/* $Id: php_apc.c,v 3.34 2004/09/12 02:56:58 rasmus Exp $ */ #ifdef PHP_WIN32 /* XXX lame hack, for some reason, the ini entries are all messed @@ -32,11 +32,22 @@ #include "php_ini.h" #include "zend_extensions.h" #include "ext/standard/info.h" +#include "SAPI.h" +/* + * Temporary Apache include until we move to the new SAPI call + * generates annoying XtOffsetOf warning because of a circular dependency order problem + */ +#if HAVE_APACHE +#include "httpd.h" +#endif + /* {{{ PHP_FUNCTION declarations */ PHP_FUNCTION(apc_cache_info); PHP_FUNCTION(apc_clear_cache); PHP_FUNCTION(apc_sma_info); +PHP_FUNCTION(apc_store); +PHP_FUNCTION(apc_fetch); /* }}} */ /* {{{ ZEND_DECLARE_MODULE_GLOBALS(apc) */ @@ -85,8 +96,10 @@ STD_PHP_INI_ENTRY("apc.shm_size", "30", PHP_INI_SYSTEM, OnUpdateInt, shm_size, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.optimization", "0", PHP_INI_SYSTEM, OnUpdateInt, optimization, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.num_files_hint", "1000", PHP_INI_SYSTEM, OnUpdateInt, num_files_hint, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.user_entries_hint", "100", PHP_INI_SYSTEM, OnUpdateInt, user_entries_hint, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateInt, gc_ttl, zend_apc_globals, apc_globals) STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, ttl, zend_apc_globals, apc_globals) +STD_PHP_INI_ENTRY("apc.user_ttl", "0", PHP_INI_SYSTEM, OnUpdateInt, user_ttl, zend_apc_globals, apc_globals) #if APC_MMAP STD_PHP_INI_ENTRY("apc.mmap_file_mask", NULL, PHP_INI_SYSTEM, OnUpdateString, mmap_file_mask, zend_apc_globals, apc_globals) #endif @@ -108,10 +121,10 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.33 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.34 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); + DISPLAY_INI_ENTRIES(); php_info_print_table_end(); - DISPLAY_INI_ENTRIES(); } /* }}} */ @@ -164,12 +177,19 @@ apc_cache_info_t* info; apc_cache_link_t* p; zval* list; + char *cache_type; + int ct_len; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cache_type, &ct_len) == FAILURE) { + return; + } + + if(!strcasecmp(cache_type,"opcode")) { + info = apc_cache_info(APCG(cache)); + } else if(!strcasecmp(cache_type,"user")) { + info = apc_cache_info(APCG(user_cache)); } - info = apc_cache_info(APCG(cache)); if(!info) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No APC info available. Perhaps APC is disabled via apc.enabled?"); RETURN_FALSE; @@ -190,9 +210,16 @@ ALLOC_INIT_ZVAL(link); array_init(link); - add_assoc_string(link, "filename", p->filename, 1); - add_assoc_long(link, "device", p->device); - add_assoc_long(link, "inode", p->inode); + if(p->type == APC_CACHE_ENTRY_FILE) { + add_assoc_string(link, "filename", p->data.file.filename, 1); + add_assoc_long(link, "device", p->data.file.device); + add_assoc_long(link, "inode", p->data.file.inode); + add_assoc_string(link, "type", "file", 1); + } else if(p->type == APC_CACHE_ENTRY_USER) { + add_assoc_string(link, "info", p->data.user.info, 1); + add_assoc_long(link, "ttl", (long)p->data.user.ttl); + add_assoc_string(link, "type", "user", 1); + } add_assoc_long(link, "num_hits", p->num_hits); add_assoc_long(link, "mtime", p->mtime); add_assoc_long(link, "creation_time", p->creation_time); @@ -212,9 +239,15 @@ ALLOC_INIT_ZVAL(link); array_init(link); - add_assoc_string(link, "filename", p->filename, 1); - add_assoc_long(link, "device", p->device); - add_assoc_long(link, "inode", p->inode); + if(p->type == APC_CACHE_ENTRY_FILE) { + add_assoc_string(link, "filename", p->data.file.filename, 1); + add_assoc_long(link, "device", p->data.file.device); + add_assoc_long(link, "inode", p->data.file.inode); + add_assoc_string(link, "type", "file", 1); + } else if(p->type == APC_CACHE_ENTRY_USER) { + add_assoc_string(link, "filename", p->data.user.info, 1); + add_assoc_string(link, "type", "user", 1); + } add_assoc_long(link, "num_hits", p->num_hits); add_assoc_long(link, "mtime", p->mtime); add_assoc_long(link, "creation_time", p->creation_time); @@ -239,6 +272,16 @@ } /* }}} */ +/* {{{ proto void apc_clear_user_cache() */ +PHP_FUNCTION(apc_clear_user_cache) +{ + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + apc_cache_clear(APCG(user_cache)); +} +/* }}} */ + /* {{{ proto array apc_sma_info() */ PHP_FUNCTION(apc_sma_info) { @@ -251,6 +294,7 @@ } info = apc_sma_info(); + if(!info) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No APC SMA info available. Perhaps APC is disabled via apc.enabled?"); RETURN_FALSE; @@ -288,11 +332,123 @@ } /* }}} */ +/* {{{ 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; + 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; + } + + printf("apc_store: user entry at 0x%lx\n",entry); + + if (!apc_cache_make_user_key(&key, strkey TSRMLS_CC)) { + apc_cache_free_entry(entry); + 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 */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif + + 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_TRUE; +} +/* }}} */ + +/* {{{ proto mixed apc_fetch(string key) + */ +PHP_FUNCTION(apc_fetch) { + char *strkey; + int strkey_len; + apc_cache_entry_t* entry; + time_t t; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &strkey, &strkey_len) == FAILURE) { + return; + } + +#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 */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif + + entry = apc_cache_user_find(APCG(user_cache), strkey, strkey_len, t); + + if(entry) { + /* Still working out if I actually need to maintain this stack */ + apc_stack_push(APCG(user_cache_stack), entry); + /* deep-copy returned shm zval to emalloc'ed return_value */ + memcpy(return_value, entry->data.user.val, sizeof(zval)); + zval_copy_ctor(return_value); + printf("apc_fetch: entry found at 0x%lx\n",entry); + } else { + printf("apc_cache_user_find returned NULL\n"); + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto mixed apc_delete(string key) + */ +PHP_FUNCTION(apc_delete) { + char *strkey; + int strkey_len; + time_t t; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &strkey, &strkey_len) == FAILURE) { + return; + } + +#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 */ + t = ((request_rec *)SG(server_context))->request_time; +#else + t = time(0); +#endif + + if(apc_cache_user_delete(APCG(user_cache), strkey, strkey_len)) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ apc_functions[] */ function_entry apc_functions[] = { PHP_FE(apc_cache_info, NULL) PHP_FE(apc_clear_cache, NULL) + PHP_FE(apc_clear_user_cache, NULL) PHP_FE(apc_sma_info, NULL) + PHP_FE(apc_store, NULL) + PHP_FE(apc_fetch, NULL) + PHP_FE(apc_delete, NULL) {NULL, NULL, NULL} }; /* }}} */
« previous php.pecl.cvs (#1819) next »