2006-05-09 10:58:38 +00:00
|
|
|
|
2009-09-29 13:42:45 +00:00
|
|
|
#if 0
|
2008-03-08 03:55:59 +00:00
|
|
|
#define XCACHE_DEBUG
|
2006-10-11 00:27:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-29 02:56:16 +00:00
|
|
|
#if 0
|
2006-10-10 00:31:50 +00:00
|
|
|
#define SHOW_DPRINT
|
2006-10-01 08:59:23 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
/* {{{ macros */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "ext/standard/info.h"
|
2006-05-27 06:53:32 +00:00
|
|
|
#include "ext/standard/md5.h"
|
2006-06-18 01:26:00 +00:00
|
|
|
#include "ext/standard/php_math.h"
|
2008-03-02 07:52:34 +00:00
|
|
|
#include "ext/standard/php_string.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "zend_extensions.h"
|
|
|
|
#include "SAPI.h"
|
|
|
|
|
|
|
|
#include "xcache.h"
|
2008-05-05 14:00:13 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
#include "ext/date/php_date.h"
|
|
|
|
#endif
|
2012-07-17 08:35:45 +00:00
|
|
|
#include "submodules/xc_optimizer.h"
|
|
|
|
#include "submodules/xc_coverager.h"
|
|
|
|
#include "submodules/xc_disassembler.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "xcache_globals.h"
|
2012-07-17 08:35:45 +00:00
|
|
|
#include "xc_processor.h"
|
|
|
|
#include "xc_const_string.h"
|
|
|
|
#include "xc_opcode_spec.h"
|
|
|
|
#include "xc_utils.h"
|
2012-07-18 03:13:28 +00:00
|
|
|
#include "xc_sandbox.h"
|
2012-07-17 08:35:45 +00:00
|
|
|
#include "util/xc_align.h"
|
|
|
|
#include "util/xc_stack.h"
|
|
|
|
#include "util/xc_vector.h"
|
|
|
|
#include "util/xc_trace.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2012-06-23 04:49:59 +00:00
|
|
|
#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > (pentry)->ctime + (time_t) (pentry)->ttl)
|
2006-05-09 10:58:38 +00:00
|
|
|
#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
|
2012-03-26 09:41:19 +00:00
|
|
|
#define LOCK(x) xc_lock((x)->lck)
|
|
|
|
#define UNLOCK(x) xc_unlock((x)->lck)
|
2006-09-03 07:36:09 +00:00
|
|
|
|
|
|
|
#define ENTER_LOCK_EX(x) \
|
2012-03-26 09:41:19 +00:00
|
|
|
xc_lock((x)->lck); \
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_try { \
|
|
|
|
do
|
2006-09-03 07:36:09 +00:00
|
|
|
#define LEAVE_LOCK_EX(x) \
|
2006-05-09 10:58:38 +00:00
|
|
|
while (0); \
|
|
|
|
} zend_catch { \
|
|
|
|
catched = 1; \
|
|
|
|
} zend_end_try(); \
|
2012-03-26 09:41:19 +00:00
|
|
|
xc_unlock((x)->lck)
|
2006-09-03 07:36:09 +00:00
|
|
|
|
|
|
|
#define ENTER_LOCK(x) do { \
|
|
|
|
int catched = 0; \
|
|
|
|
ENTER_LOCK_EX(x)
|
|
|
|
#define LEAVE_LOCK(x) \
|
|
|
|
LEAVE_LOCK_EX(x); \
|
|
|
|
if (catched) { \
|
|
|
|
zend_bailout(); \
|
|
|
|
} \
|
2006-05-09 10:58:38 +00:00
|
|
|
} while(0)
|
2006-09-03 07:36:09 +00:00
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ globals */
|
2006-09-09 00:56:44 +00:00
|
|
|
static char *xc_shm_scheme = NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
static char *xc_mmap_path = NULL;
|
|
|
|
static char *xc_coredump_dir = NULL;
|
2012-07-16 08:41:38 +00:00
|
|
|
static zend_bool xc_disable_on_crash = 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2012-07-17 08:35:45 +00:00
|
|
|
static xc_hash_t xc_php_hcache = { 0, 0, 0 };
|
|
|
|
static xc_hash_t xc_php_hentry = { 0, 0, 0 };
|
|
|
|
static xc_hash_t xc_var_hcache = { 0, 0, 0 };
|
|
|
|
static xc_hash_t xc_var_hentry = { 0, 0, 0 };
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
static zend_ulong xc_php_ttl = 0;
|
|
|
|
static zend_ulong xc_var_maxttl = 0;
|
|
|
|
|
|
|
|
enum { xc_deletes_gc_interval = 120 };
|
|
|
|
static zend_ulong xc_php_gc_interval = 0;
|
|
|
|
static zend_ulong xc_var_gc_interval = 0;
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* total size */
|
|
|
|
static zend_ulong xc_php_size = 0;
|
|
|
|
static zend_ulong xc_var_size = 0;
|
|
|
|
|
2012-07-16 08:41:38 +00:00
|
|
|
static xc_shm_t *xc_shm = NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
static xc_cache_t **xc_php_caches = NULL;
|
|
|
|
static xc_cache_t **xc_var_caches = NULL;
|
|
|
|
|
|
|
|
static zend_bool xc_initized = 0;
|
2008-03-02 05:43:01 +00:00
|
|
|
static time_t xc_init_time = 0;
|
|
|
|
static long unsigned xc_init_instance_id = 0;
|
|
|
|
#ifdef ZTS
|
|
|
|
static long unsigned xc_init_instance_subid = 0;
|
|
|
|
#endif
|
2007-05-31 03:48:08 +00:00
|
|
|
static zend_compile_file_t *origin_compile_file = NULL;
|
2007-05-31 03:23:20 +00:00
|
|
|
static zend_compile_file_t *old_compile_file = NULL;
|
|
|
|
static zend_llist_element *xc_llist_zend_extension = NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
static zend_bool xc_test = 0;
|
|
|
|
static zend_bool xc_readonly_protection = 0;
|
|
|
|
|
2006-09-20 00:24:42 +00:00
|
|
|
zend_bool xc_have_op_array_ctor = 0;
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
static zend_bool xc_module_gotup = 0;
|
|
|
|
static zend_bool xc_zend_extension_gotup = 0;
|
2006-11-17 17:21:46 +00:00
|
|
|
static zend_bool xc_zend_extension_faked = 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
#if !COMPILE_DL_XCACHE
|
|
|
|
# define zend_extension_entry xcache_zend_extension_entry
|
|
|
|
#endif
|
|
|
|
ZEND_DLEXPORT zend_extension zend_extension_entry;
|
2012-07-17 08:35:45 +00:00
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(xcache)
|
2012-03-28 08:48:20 +00:00
|
|
|
|
|
|
|
typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
|
2012-04-01 09:27:38 +00:00
|
|
|
/* any function in *_unlocked is only safe be called within locked (single thread access) area */
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_php_add_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_data_php_t **head = &(cache->phps[php->hvalue]);
|
2006-12-09 16:27:03 +00:00
|
|
|
php->next = *head;
|
|
|
|
*head = php;
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->phps_count ++;
|
2006-12-09 16:27:03 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_data_php_t *xc_php_store_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
|
|
|
xc_entry_data_php_t *stored_php;
|
|
|
|
|
|
|
|
php->hits = 0;
|
|
|
|
php->refcount = 0;
|
2012-03-28 08:48:20 +00:00
|
|
|
stored_php = xc_processor_store_xc_entry_data_php_t(cache, php TSRMLS_CC);
|
2006-12-09 16:27:03 +00:00
|
|
|
if (stored_php) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_php_add_unlocked(cache, stored_php);
|
2006-12-09 16:27:03 +00:00
|
|
|
return stored_php;
|
|
|
|
}
|
|
|
|
else {
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->ooms ++;
|
2006-12-09 16:27:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_data_php_t *xc_php_find_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
|
|
|
xc_entry_data_php_t *p;
|
2012-03-28 08:48:20 +00:00
|
|
|
for (p = cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) {
|
2012-03-26 11:14:09 +00:00
|
|
|
if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) {
|
2006-12-09 16:27:03 +00:00
|
|
|
p->hits ++;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_php_free_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->mem->handlers->free(cache->mem, (xc_entry_data_php_t *)php);
|
2006-12-09 16:27:03 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_php_addref_unlocked(xc_entry_data_php_t *php) /* {{{ */
|
2006-12-10 08:18:09 +00:00
|
|
|
{
|
|
|
|
php->refcount ++;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_php_release_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
|
|
|
if (-- php->refcount == 0) {
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_data_php_t **pp = &(cache->phps[php->hvalue]);
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_entry_data_php_t *p;
|
|
|
|
for (p = *pp; p; pp = &(p->next), p = p->next) {
|
2012-03-26 11:14:09 +00:00
|
|
|
if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) {
|
2006-12-09 16:27:03 +00:00
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_php_free_unlocked(cache, php);
|
2006-12-09 16:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-07-13 02:53:11 +00:00
|
|
|
static inline int xc_entry_equal_unlocked(xc_entry_type_t type, const xc_entry_t *entry1, const xc_entry_t *entry2 TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2012-04-01 09:28:23 +00:00
|
|
|
/* this function isn't required but can be in unlocked */
|
2012-03-28 08:48:20 +00:00
|
|
|
switch (type) {
|
2006-05-09 10:58:38 +00:00
|
|
|
case XC_TYPE_PHP:
|
2012-03-27 16:07:50 +00:00
|
|
|
{
|
|
|
|
const xc_entry_php_t *php_entry1 = (const xc_entry_php_t *) entry1;
|
|
|
|
const xc_entry_php_t *php_entry2 = (const xc_entry_php_t *) entry2;
|
2012-07-13 02:40:55 +00:00
|
|
|
if (php_entry1->file_inode && php_entry2->file_inode) {
|
|
|
|
zend_bool inodeIsSame = php_entry1->file_inode == php_entry2->file_inode
|
|
|
|
&& php_entry1->file_device == php_entry2->file_device;
|
|
|
|
if (XG(experimental)) {
|
|
|
|
/* new experimental behavior: quick check by inode, first */
|
|
|
|
if (!inodeIsSame) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and then opened_path compare */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* old behavior: inode check only */
|
|
|
|
return inodeIsSame;
|
|
|
|
}
|
2006-09-13 12:22:57 +00:00
|
|
|
}
|
2012-03-27 16:07:50 +00:00
|
|
|
}
|
2012-07-13 02:40:55 +00:00
|
|
|
|
2012-03-29 09:24:40 +00:00
|
|
|
assert(IS_ABSOLUTE_PATH(entry1->name.str.val, entry1->name.str.len));
|
|
|
|
assert(IS_ABSOLUTE_PATH(entry2->name.str.val, entry2->name.str.len));
|
2012-03-29 05:51:14 +00:00
|
|
|
|
2012-07-13 02:40:55 +00:00
|
|
|
return entry1->name.str.len == entry2->name.str.len
|
|
|
|
&& memcmp(entry1->name.str.val, entry2->name.str.val, entry1->name.str.len + 1) == 0;
|
2012-03-29 05:51:14 +00:00
|
|
|
|
2012-03-29 09:24:40 +00:00
|
|
|
case XC_TYPE_VAR:
|
2012-03-29 05:51:14 +00:00
|
|
|
#ifdef IS_UNICODE
|
2012-03-29 09:24:40 +00:00
|
|
|
if (entry1->name_type != entry2->name_type) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-13 02:40:55 +00:00
|
|
|
|
|
|
|
if (entry1->name_type == IS_UNICODE) {
|
|
|
|
return entry1->name.ustr.len == entry2->name.ustr.len
|
|
|
|
&& memcmp(entry1->name.ustr.val, entry2->name.ustr.val, (entry1->name.ustr.len + 1) * sizeof(UChar)) == 0;
|
2012-03-29 05:51:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-13 02:40:55 +00:00
|
|
|
return entry1->name.str.len == entry2->name.str.len
|
|
|
|
&& memcmp(entry1->name.str.val, entry2->name.str.val, entry1->name.str.len + 1) == 0;
|
2012-03-29 09:24:40 +00:00
|
|
|
break;
|
2009-08-26 02:18:14 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static inline int xc_entry_has_prefix_unlocked(xc_entry_type_t type, xc_entry_t *entry, zval *prefix) /* {{{ */
|
2009-08-26 02:18:14 +00:00
|
|
|
{
|
2012-04-01 09:28:23 +00:00
|
|
|
/* this function isn't required but can be in unlocked */
|
2009-08-26 02:18:14 +00:00
|
|
|
|
|
|
|
#ifdef IS_UNICODE
|
2012-03-28 08:48:20 +00:00
|
|
|
if (entry->name_type != prefix->type) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-26 02:18:14 +00:00
|
|
|
|
2012-03-28 08:48:20 +00:00
|
|
|
if (entry->name_type == IS_UNICODE) {
|
|
|
|
if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0;
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
2012-03-28 08:48:20 +00:00
|
|
|
if (prefix->type != IS_STRING) {
|
|
|
|
return 0;
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2012-03-28 08:48:20 +00:00
|
|
|
if (entry->name.str.len < Z_STRLEN_P(prefix)) {
|
|
|
|
return 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
2012-03-28 08:48:20 +00:00
|
|
|
|
|
|
|
return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_entry_add_unlocked(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_t **head = &(cache->entries[entryslotid]);
|
2012-03-29 06:14:57 +00:00
|
|
|
entry->next = *head;
|
|
|
|
*head = entry;
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->entries_count ++;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_t *xc_entry_store_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2012-03-29 06:14:57 +00:00
|
|
|
xc_entry_t *stored_entry;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2012-03-29 06:14:57 +00:00
|
|
|
entry->hits = 0;
|
|
|
|
entry->ctime = XG(request_time);
|
|
|
|
entry->atime = XG(request_time);
|
|
|
|
stored_entry = type == XC_TYPE_PHP
|
|
|
|
? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache, (xc_entry_php_t *) entry TSRMLS_CC)
|
|
|
|
: (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache, (xc_entry_var_t *) entry TSRMLS_CC);
|
|
|
|
if (stored_entry) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_add_unlocked(cache, entryslotid, stored_entry);
|
2012-06-28 07:45:40 +00:00
|
|
|
++cache->updates;
|
2012-03-29 06:14:57 +00:00
|
|
|
return stored_entry;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->ooms ++;
|
2006-05-09 10:58:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_php_t *xc_entry_php_store_unlocked(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_php_t *entry_php TSRMLS_DC) /* {{{ */
|
2012-03-27 16:07:50 +00:00
|
|
|
{
|
2012-04-01 09:27:38 +00:00
|
|
|
return (xc_entry_php_t *) xc_entry_store_unlocked(XC_TYPE_PHP, cache, entryslotid, (xc_entry_t *) entry_php TSRMLS_CC);
|
2012-03-27 16:07:50 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_var_t *xc_entry_var_store_unlocked(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_var_t *entry_var TSRMLS_DC) /* {{{ */
|
2012-03-28 09:30:46 +00:00
|
|
|
{
|
2012-04-01 09:27:38 +00:00
|
|
|
return (xc_entry_var_t *) xc_entry_store_unlocked(XC_TYPE_VAR, cache, entryslotid, (xc_entry_t *) entry_var TSRMLS_CC);
|
2012-03-28 09:30:46 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_entry_free_real_unlocked(xc_entry_type_t type, xc_cache_t *cache, volatile xc_entry_t *entry) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
if (type == XC_TYPE_PHP) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_php_release_unlocked(cache, ((xc_entry_php_t *) entry)->php);
|
2006-12-09 16:27:03 +00:00
|
|
|
}
|
2012-03-29 06:14:57 +00:00
|
|
|
cache->mem->handlers->free(cache->mem, (xc_entry_t *)entry);
|
2006-12-09 16:27:03 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_entry_free_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_entry_t *entry TSRMLS_DC) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->entries_count --;
|
2012-03-29 06:14:57 +00:00
|
|
|
if ((type == XC_TYPE_PHP ? ((xc_entry_php_t *) entry)->refcount : 0) == 0) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_free_real_unlocked(type, cache, entry);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-29 06:14:57 +00:00
|
|
|
entry->next = cache->deletes;
|
|
|
|
cache->deletes = entry;
|
|
|
|
entry->dtime = XG(request_time);
|
2012-03-28 08:48:20 +00:00
|
|
|
cache->deletes_count ++;
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_entry_remove_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_t **pp = &(cache->entries[entryslotid]);
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_entry_t *p;
|
2006-08-30 00:31:03 +00:00
|
|
|
for (p = *pp; p; pp = &(p->next), p = p->next) {
|
2012-07-13 02:53:11 +00:00
|
|
|
if (xc_entry_equal_unlocked(type, entry, p TSRMLS_CC)) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_free_unlocked(type, cache, entry TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static xc_entry_t *xc_entry_find_unlocked(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *entry TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
xc_entry_t *p;
|
2012-03-28 08:48:20 +00:00
|
|
|
for (p = cache->entries[entryslotid]; p; p = p->next) {
|
2012-07-13 02:53:11 +00:00
|
|
|
if (xc_entry_equal_unlocked(type, entry, p TSRMLS_CC)) {
|
2012-03-27 16:07:50 +00:00
|
|
|
zend_bool fresh;
|
2012-03-28 08:48:20 +00:00
|
|
|
switch (type) {
|
2012-03-27 16:07:50 +00:00
|
|
|
case XC_TYPE_PHP:
|
|
|
|
{
|
|
|
|
xc_entry_php_t *p_php = (xc_entry_php_t *) p;
|
2012-03-29 06:14:57 +00:00
|
|
|
xc_entry_php_t *entry_php = (xc_entry_php_t *) entry;
|
|
|
|
fresh = p_php->file_mtime == entry_php->file_mtime && p_php->file_size == entry_php->file_size;
|
2012-03-27 16:07:50 +00:00
|
|
|
}
|
2012-03-28 13:01:47 +00:00
|
|
|
break;
|
2012-03-27 16:07:50 +00:00
|
|
|
|
|
|
|
case XC_TYPE_VAR:
|
2012-03-28 13:01:47 +00:00
|
|
|
{
|
|
|
|
fresh = !VAR_ENTRY_EXPIRED(p);
|
|
|
|
}
|
2012-03-27 16:07:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fresh) {
|
2006-05-09 10:58:38 +00:00
|
|
|
p->hits ++;
|
|
|
|
p->atime = XG(request_time);
|
|
|
|
return p;
|
|
|
|
}
|
2012-03-27 16:07:50 +00:00
|
|
|
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_remove_unlocked(type, cache, entryslotid, p TSRMLS_CC);
|
2012-03-27 16:07:50 +00:00
|
|
|
return NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_entry_hold_php_unlocked(xc_cache_t *cache, xc_entry_php_t *entry TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2012-03-28 16:15:21 +00:00
|
|
|
TRACE("hold %d:%s", entry->file_inode, entry->entry.name.str.val);
|
|
|
|
entry->refcount ++;
|
|
|
|
xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)entry);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2008-02-17 16:49:46 +00:00
|
|
|
static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */
|
|
|
|
{
|
|
|
|
if (val + 1 >= count) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return val + 1;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t period, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
time_t n = XG(request_time) / period;
|
|
|
|
if (*curtime != n) {
|
|
|
|
zend_uint target_slot = n % count;
|
|
|
|
if (n - *curtime > period) {
|
|
|
|
memset(counters, 0, sizeof(counters[0]) * count);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zend_uint slot;
|
|
|
|
for (slot = advance_wrapped(*curslot, count);
|
|
|
|
slot != target_slot;
|
|
|
|
slot = advance_wrapped(slot, count)) {
|
|
|
|
counters[slot] = 0;
|
|
|
|
}
|
|
|
|
counters[target_slot] = 0;
|
|
|
|
}
|
|
|
|
*curtime = n;
|
|
|
|
*curslot = target_slot;
|
|
|
|
}
|
|
|
|
counters[*curslot] ++;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_cache_hit_unlocked(xc_cache_t *cache TSRMLS_DC) /* {{{ */
|
2008-02-17 16:49:46 +00:00
|
|
|
{
|
|
|
|
cache->hits ++;
|
|
|
|
|
|
|
|
xc_counters_inc(&cache->hits_by_hour_cur_time
|
|
|
|
, &cache->hits_by_hour_cur_slot, 60 * 60
|
|
|
|
, cache->hits_by_hour
|
|
|
|
, sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0])
|
|
|
|
TSRMLS_CC);
|
|
|
|
|
|
|
|
xc_counters_inc(&cache->hits_by_second_cur_time
|
|
|
|
, &cache->hits_by_second_cur_slot
|
|
|
|
, 1
|
|
|
|
, cache->hits_by_second
|
|
|
|
, sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0])
|
|
|
|
TSRMLS_CC);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
/* helper function that loop through each entry */
|
2012-03-29 09:24:40 +00:00
|
|
|
#define XC_ENTRY_APPLY_FUNC(name) zend_bool name(xc_entry_t *entry TSRMLS_DC)
|
2012-04-01 09:27:38 +00:00
|
|
|
typedef XC_ENTRY_APPLY_FUNC((*cache_apply_unlocked_func_t));
|
2012-04-01 09:28:23 +00:00
|
|
|
static void xc_entry_apply_unlocked(xc_entry_type_t type, xc_cache_t *cache, cache_apply_unlocked_func_t apply_func TSRMLS_DC) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
xc_entry_t *p, **pp;
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
for (i = 0, c = cache->hentry->size; i < c; i ++) {
|
|
|
|
pp = &(cache->entries[i]);
|
2006-09-06 06:41:04 +00:00
|
|
|
for (p = *pp; p; p = *pp) {
|
2006-08-30 00:31:03 +00:00
|
|
|
if (apply_func(p TSRMLS_CC)) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_free_unlocked(type, cache, p TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pp = &(p->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#define XC_CACHE_APPLY_FUNC(name) void name(xc_cache_t *cache TSRMLS_DC)
|
|
|
|
/* call graph:
|
2012-04-01 09:28:23 +00:00
|
|
|
* xc_gc_expires_php -> xc_gc_expires_one -> xc_entry_apply_unlocked -> xc_gc_expires_php_entry_unlocked
|
|
|
|
* xc_gc_expires_var -> xc_gc_expires_one -> xc_entry_apply_unlocked -> xc_gc_expires_var_entry_unlocked
|
2006-08-30 00:31:03 +00:00
|
|
|
*/
|
2012-04-01 09:27:38 +00:00
|
|
|
static XC_ENTRY_APPLY_FUNC(xc_gc_expires_php_entry_unlocked) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("ttl %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) entry->atime, xc_php_ttl);
|
2012-06-23 04:49:59 +00:00
|
|
|
if (XG(request_time) > entry->atime + (time_t) xc_php_ttl) {
|
2006-08-30 00:31:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static XC_ENTRY_APPLY_FUNC(xc_gc_expires_var_entry_unlocked) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
if (VAR_ENTRY_EXPIRED(entry)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_gc_expires_one(xc_entry_type_t type, xc_cache_t *cache, zend_ulong gc_interval, cache_apply_unlocked_func_t apply_func TSRMLS_DC) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval);
|
2012-06-23 04:49:59 +00:00
|
|
|
if (XG(request_time) >= cache->last_gc_expires + (time_t) gc_interval) {
|
2006-08-30 00:31:03 +00:00
|
|
|
ENTER_LOCK(cache) {
|
2012-06-23 04:49:59 +00:00
|
|
|
if (XG(request_time) >= cache->last_gc_expires + (time_t) gc_interval) {
|
2006-08-30 00:31:03 +00:00
|
|
|
cache->last_gc_expires = XG(request_time);
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_apply_unlocked(type, cache, apply_func TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
} LEAVE_LOCK(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-02 02:08:41 +00:00
|
|
|
static void xc_gc_expires_php(TSRMLS_D) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (!xc_php_ttl || !xc_php_gc_interval || !xc_php_caches) {
|
2006-08-30 00:31:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, c = xc_php_hcache.size; i < c; i ++) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_gc_expires_one(XC_TYPE_PHP, xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_unlocked TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-02 02:08:41 +00:00
|
|
|
static void xc_gc_expires_var(TSRMLS_D) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (!xc_var_gc_interval || !xc_var_caches) {
|
2006-08-30 00:31:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, c = xc_var_hcache.size; i < c; i ++) {
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_gc_expires_one(XC_TYPE_VAR, xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_unlocked TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-04-01 09:27:38 +00:00
|
|
|
static XC_CACHE_APPLY_FUNC(xc_gc_delete_unlocked) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
xc_entry_t *p, **pp;
|
|
|
|
|
|
|
|
pp = &cache->deletes;
|
2006-09-07 11:40:09 +00:00
|
|
|
for (p = *pp; p; p = *pp) {
|
2012-03-27 16:07:50 +00:00
|
|
|
xc_entry_php_t *entry = (xc_entry_php_t *) p;
|
2006-08-30 00:31:03 +00:00
|
|
|
if (XG(request_time) - p->dtime > 3600) {
|
2012-03-27 16:07:50 +00:00
|
|
|
entry->refcount = 0;
|
2006-08-30 00:31:03 +00:00
|
|
|
/* issue warning here */
|
|
|
|
}
|
2012-03-27 16:07:50 +00:00
|
|
|
if (entry->refcount == 0) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
2006-08-30 00:31:03 +00:00
|
|
|
*pp = p->next;
|
|
|
|
cache->deletes_count --;
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_entry_free_real_unlocked(XC_TYPE_PHP, cache, p);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pp = &(p->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static XC_CACHE_APPLY_FUNC(xc_gc_deletes_one) /* {{{ */
|
|
|
|
{
|
|
|
|
if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) {
|
|
|
|
ENTER_LOCK(cache) {
|
|
|
|
if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) {
|
2006-09-06 01:40:49 +00:00
|
|
|
cache->last_gc_deletes = XG(request_time);
|
2012-04-01 09:27:38 +00:00
|
|
|
xc_gc_delete_unlocked(cache TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
} LEAVE_LOCK(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_gc_deletes(TSRMLS_D) /* {{{ */
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (xc_php_caches) {
|
|
|
|
for (i = 0, c = xc_php_hcache.size; i < c; i ++) {
|
|
|
|
xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC);
|
|
|
|
}
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (xc_var_caches) {
|
|
|
|
for (i = 0, c = xc_var_hcache.size; i < c; i ++) {
|
|
|
|
xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC);
|
|
|
|
}
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* helper functions for user functions */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_fillinfo_unlocked(int cachetype, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2008-02-17 16:49:46 +00:00
|
|
|
zval *blocks, *hits;
|
2012-07-17 08:54:15 +00:00
|
|
|
size_t i;
|
2006-05-09 10:58:38 +00:00
|
|
|
const xc_block_t *b;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
xc_memsize_t avail = 0;
|
|
|
|
#endif
|
|
|
|
xc_mem_t *mem = cache->mem;
|
2006-09-09 00:56:44 +00:00
|
|
|
const xc_mem_handlers_t *handlers = mem->handlers;
|
2007-04-07 03:21:34 +00:00
|
|
|
zend_ulong interval;
|
|
|
|
if (cachetype == XC_TYPE_PHP) {
|
|
|
|
interval = xc_php_ttl ? xc_php_gc_interval : 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
interval = xc_var_gc_interval;
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("slots"), cache->hentry->size);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling);
|
2012-06-28 07:45:40 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("updates"), cache->updates);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("misses"), cache->updates); /* deprecated */
|
2006-05-09 10:58:38 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("hits"), cache->hits);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("clogs"), cache->clogs);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("ooms"), cache->ooms);
|
2007-07-14 05:06:10 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("errors"), cache->errors);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("cached"), cache->entries_count);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("deleted"), cache->deletes_count);
|
2006-08-31 00:23:20 +00:00
|
|
|
if (interval) {
|
2007-04-07 03:21:34 +00:00
|
|
|
time_t gc = (cache->last_gc_expires + interval) - XG(request_time);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("gc"), gc > 0 ? gc : 0);
|
2006-08-31 00:23:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_assoc_null_ex(return_value, ZEND_STRS("gc"));
|
|
|
|
}
|
2008-02-17 16:49:46 +00:00
|
|
|
MAKE_STD_ZVAL(hits);
|
|
|
|
array_init(hits);
|
|
|
|
for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) {
|
|
|
|
add_next_index_long(hits, (long) cache->hits_by_hour[i]);
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits);
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(hits);
|
|
|
|
array_init(hits);
|
|
|
|
for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) {
|
|
|
|
add_next_index_long(hits, (long) cache->hits_by_second[i]);
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(blocks);
|
|
|
|
array_init(blocks);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("size"), handlers->size(mem));
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem));
|
2006-05-09 10:58:38 +00:00
|
|
|
add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) {
|
2006-05-09 10:58:38 +00:00
|
|
|
zval *bi;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(bi);
|
|
|
|
array_init(bi);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
add_assoc_long_ex(bi, ZEND_STRS("size"), handlers->block_size(b));
|
|
|
|
add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b));
|
2006-05-09 10:58:38 +00:00
|
|
|
add_next_index_zval(blocks, bi);
|
|
|
|
#ifndef NDEBUG
|
2006-09-09 00:56:44 +00:00
|
|
|
avail += handlers->block_size(b);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks);
|
2008-07-04 08:38:12 +00:00
|
|
|
#ifndef NDEBUG
|
2006-09-09 00:56:44 +00:00
|
|
|
assert(avail == handlers->avail(mem));
|
2008-07-04 08:38:12 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2012-04-01 09:27:38 +00:00
|
|
|
static void xc_fillentry_unlocked(xc_entry_type_t type, const xc_entry_t *entry, xc_hash_value_t entryslotid, int del, zval *list TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
zval* ei;
|
2012-03-27 16:07:50 +00:00
|
|
|
const xc_entry_data_php_t *php;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(ei);
|
|
|
|
array_init(ei);
|
|
|
|
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("hits"), entry->hits);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("ctime"), entry->ctime);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("atime"), entry->atime);
|
2012-03-28 08:48:20 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("hvalue"), entryslotid);
|
2006-09-08 13:13:59 +00:00
|
|
|
if (del) {
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
do {
|
|
|
|
zval *zv;
|
|
|
|
ALLOC_INIT_ZVAL(zv);
|
|
|
|
switch (entry->name_type) {
|
|
|
|
case IS_UNICODE:
|
2012-06-26 17:26:48 +00:00
|
|
|
ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1);
|
2006-05-09 10:58:38 +00:00
|
|
|
break;
|
|
|
|
case IS_STRING:
|
|
|
|
ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
zv->type = entry->name_type;
|
|
|
|
add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
|
|
|
|
} while (0);
|
|
|
|
#else
|
|