2006-05-09 10:58:38 +00:00
|
|
|
#ifndef __XCACHE_H
|
|
|
|
#define __XCACHE_H
|
|
|
|
#define XCACHE_NAME "XCache"
|
2006-12-09 03:49:53 +00:00
|
|
|
#define XCACHE_VERSION "2.0.0-dev"
|
2006-05-09 10:58:38 +00:00
|
|
|
#define XCACHE_AUTHOR "mOo"
|
2007-07-01 08:54:53 +00:00
|
|
|
#define XCACHE_COPYRIGHT "Copyright (c) 2005-2007"
|
2006-05-09 10:58:38 +00:00
|
|
|
#define XCACHE_URL "http://xcache.lighttpd.net"
|
|
|
|
|
|
|
|
#include <php.h>
|
|
|
|
#include <zend_compile.h>
|
|
|
|
#include <zend_API.h>
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "zend_hash.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2006-09-09 00:56:44 +00:00
|
|
|
#include "xc_shm.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "lock.h"
|
|
|
|
|
2006-09-13 12:22:57 +00:00
|
|
|
#define HAVE_INODE
|
2006-05-09 10:58:38 +00:00
|
|
|
#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
|
|
|
|
# define ZEND_ENGINE_2_1
|
|
|
|
#endif
|
2006-06-11 02:49:31 +00:00
|
|
|
#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
|
|
|
|
# define ZEND_ENGINE_2_2
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-05-25 02:36:08 +00:00
|
|
|
#define NOTHING
|
2006-05-09 10:58:38 +00:00
|
|
|
/* ZendEngine code Switcher */
|
|
|
|
#ifndef ZEND_ENGINE_2
|
|
|
|
# define ZESW(v1, v2) v1
|
|
|
|
#else
|
|
|
|
# define ZESW(v1, v2) v2
|
|
|
|
#endif
|
|
|
|
|
2006-10-21 06:06:38 +00:00
|
|
|
/* {{{ dirty fix for PHP 6 */
|
|
|
|
#ifdef add_assoc_long_ex
|
|
|
|
static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
|
|
|
|
{
|
|
|
|
add_assoc_long_ex(arg, key, key_len, value);
|
|
|
|
}
|
|
|
|
# undef add_assoc_long_ex
|
|
|
|
# define add_assoc_long_ex my_add_assoc_long_ex
|
|
|
|
#endif
|
|
|
|
#ifdef add_assoc_bool_ex
|
|
|
|
static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
|
|
|
|
{
|
|
|
|
add_assoc_bool_ex(arg, key, key_len, value);
|
|
|
|
}
|
|
|
|
# undef add_assoc_bool_ex
|
|
|
|
# define add_assoc_bool_ex my_add_assoc_bool_ex
|
|
|
|
#endif
|
|
|
|
#ifdef add_assoc_null_ex
|
|
|
|
static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
|
|
|
|
{
|
|
|
|
add_assoc_null_ex(arg, key, key_len);
|
|
|
|
}
|
|
|
|
# undef add_assoc_null_ex
|
|
|
|
# define add_assoc_null_ex my_add_assoc_null_ex
|
|
|
|
#endif
|
|
|
|
/* }}} */
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* unicode */
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
# define UNISW(text, unicode) unicode
|
|
|
|
#else
|
|
|
|
# define UNISW(text, unicode) text
|
|
|
|
#endif
|
|
|
|
#define BUCKET_KEY_SIZE(b) \
|
|
|
|
(UNISW( \
|
|
|
|
(b)->nKeyLength, \
|
|
|
|
((b)->key.type == IS_UNICODE) \
|
|
|
|
? UBYTES(b->nKeyLength) \
|
|
|
|
: b->nKeyLength \
|
|
|
|
))
|
2006-09-29 00:09:51 +00:00
|
|
|
#define BUCKET_KEY_S(b) (UNISW((b)->arKey, (b)->key.arKey.s))
|
|
|
|
#define BUCKET_KEY_U(b) (UNISW((b)->arKey, (b)->key.arKey.u))
|
|
|
|
#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING, (b)->key.type))
|
2006-05-13 01:51:59 +00:00
|
|
|
#ifdef IS_UNICODE
|
2006-08-27 06:48:54 +00:00
|
|
|
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
|
2006-05-13 01:51:59 +00:00
|
|
|
#else
|
2006-05-24 07:52:48 +00:00
|
|
|
# define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
|
2006-05-13 01:51:59 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
|
|
|
|
|
|
|
|
#ifndef IS_UNICODE
|
|
|
|
typedef char *zstr;
|
2006-08-27 05:09:02 +00:00
|
|
|
# define ZSTR_S(s) (s)
|
|
|
|
# define ZSTR_U(s) (s)
|
|
|
|
# define ZSTR_V(s) (s)
|
|
|
|
# define ZSTR_PS(s) (s)
|
|
|
|
# define ZSTR_PU(s) (s)
|
|
|
|
# define ZSTR_PV(s) (s)
|
2006-05-09 10:58:38 +00:00
|
|
|
#else
|
2006-08-27 05:09:02 +00:00
|
|
|
# define ZSTR_S(zs) ((zs).s)
|
|
|
|
# define ZSTR_U(zs) ((zs).u)
|
|
|
|
# define ZSTR_V(zs) ((zs).v)
|
|
|
|
# define ZSTR_PS(pzs) ((pzs)->s)
|
|
|
|
# define ZSTR_PU(pzs) ((pzs)->u)
|
|
|
|
# define ZSTR_PV(pzs) ((pzs)->v)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ZSTR
|
|
|
|
# define ZSTR(s) (s)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef Z_UNIVAL
|
|
|
|
# define Z_UNIVAL(zval) (zval).value.str.val
|
|
|
|
# define Z_UNILEN(zval) (zval).value.str.len
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* {{{ u hash wrapper */
|
|
|
|
#ifndef IS_UNICODE
|
|
|
|
# define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
|
|
|
|
zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
|
|
|
|
|
2006-07-09 12:47:31 +00:00
|
|
|
# define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
|
|
|
|
zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
# define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
|
|
|
|
zend_hash_find(ht, arKey, nKeyLength, pData)
|
|
|
|
|
2006-09-29 00:09:51 +00:00
|
|
|
# define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
|
|
|
|
zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
# define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
|
|
|
|
add_assoc_zval_ex(arg, key, key_len, value)
|
|
|
|
|
2006-10-29 02:05:01 +00:00
|
|
|
# define zend_u_is_auto_global(type, name, name_len) \
|
|
|
|
zend_is_auto_global(name, name_len)
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
|
|
|
|
#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef ulong xc_hash_value_t;
|
|
|
|
typedef struct {
|
|
|
|
int bits;
|
|
|
|
int size;
|
|
|
|
int mask;
|
|
|
|
} xc_hash_t;
|
|
|
|
|
|
|
|
/* the class entry type to be stored in class_table */
|
|
|
|
typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
|
|
|
|
|
|
|
|
/* xc_cest_t to (zend_class_entry*) */
|
|
|
|
#define CestToCePtr(st) (ZESW(\
|
|
|
|
&(st), \
|
|
|
|
st \
|
|
|
|
) )
|
|
|
|
|
|
|
|
/* ZCEP=zend class entry ptr */
|
|
|
|
#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
|
|
|
|
(pce)->refcount, \
|
|
|
|
&((pce)->refcount) \
|
|
|
|
))
|
|
|
|
|
|
|
|
#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
|
|
|
|
|
|
|
|
typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
|
|
|
|
|
|
|
|
typedef struct _xc_entry_t xc_entry_t;
|
2006-12-09 16:27:03 +00:00
|
|
|
typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
|
|
|
|
/* {{{ xc_cache_t */
|
2006-05-24 07:52:48 +00:00
|
|
|
typedef struct {
|
2006-05-09 10:58:38 +00:00
|
|
|
int cacheid;
|
|
|
|
xc_hash_t *hcache; /* hash to cacheid */
|
|
|
|
|
2006-05-24 07:52:48 +00:00
|
|
|
time_t compiling;
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_ulong misses;
|
|
|
|
zend_ulong hits;
|
|
|
|
zend_ulong clogs;
|
|
|
|
zend_ulong ooms;
|
|
|
|
xc_lock_t *lck;
|
|
|
|
xc_shm_t *shm; /* to which shm contains us */
|
|
|
|
xc_mem_t *mem; /* to which mem contains us */
|
|
|
|
|
|
|
|
xc_entry_t **entries;
|
2006-05-27 03:05:10 +00:00
|
|
|
int entries_count;
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_entry_data_php_t **phps;
|
|
|
|
int phps_count;
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_entry_t *deletes;
|
2006-05-27 03:05:10 +00:00
|
|
|
int deletes_count;
|
2006-12-09 16:27:03 +00:00
|
|
|
xc_hash_t *hentry; /* hash settings to entry */
|
|
|
|
xc_hash_t *hphp; /* hash settings to php */
|
2006-08-30 00:31:03 +00:00
|
|
|
|
|
|
|
time_t last_gc_deletes;
|
|
|
|
time_t last_gc_expires;
|
2006-05-09 10:58:38 +00:00
|
|
|
} xc_cache_t;
|
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_classinfo_t */
|
|
|
|
typedef struct {
|
2006-05-24 12:38:55 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar type;
|
|
|
|
#endif
|
2006-08-27 05:09:02 +00:00
|
|
|
zstr key;
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_uint key_size;
|
|
|
|
xc_cest_t cest;
|
2006-10-04 00:38:45 +00:00
|
|
|
int oplineno;
|
2006-05-09 10:58:38 +00:00
|
|
|
} xc_classinfo_t;
|
|
|
|
/* }}} */
|
2006-07-16 11:07:57 +00:00
|
|
|
#ifdef HAVE_XCACHE_CONSTANT
|
|
|
|
/* {{{ xc_constinfo_t */
|
|
|
|
typedef struct {
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar type;
|
|
|
|
#endif
|
2006-08-27 05:09:02 +00:00
|
|
|
zstr key;
|
2006-07-16 11:07:57 +00:00
|
|
|
zend_uint key_size;
|
|
|
|
zend_constant constant;
|
|
|
|
} xc_constinfo_t;
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
/* {{{ xc_funcinfo_t */
|
|
|
|
typedef struct {
|
2006-05-24 12:38:55 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar type;
|
|
|
|
#endif
|
2006-08-27 05:09:02 +00:00
|
|
|
zstr key;
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_uint key_size;
|
|
|
|
zend_function func;
|
|
|
|
} xc_funcinfo_t;
|
|
|
|
/* }}} */
|
2006-10-29 02:05:01 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
/* {{{ xc_autoglobal_t */
|
|
|
|
typedef struct {
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar type;
|
|
|
|
#endif
|
|
|
|
zstr key;
|
|
|
|
zend_uint key_len;
|
|
|
|
} xc_autoglobal_t;
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
|
2006-12-09 16:27:03 +00:00
|
|
|
typedef char xc_md5sum_t[16];
|
2006-05-09 10:58:38 +00:00
|
|
|
/* {{{ xc_entry_data_php_t */
|
2006-12-09 16:27:03 +00:00
|
|
|
struct _xc_entry_data_php_t {
|
|
|
|
xc_hash_value_t hvalue; /* hash of md5 */
|
|
|
|
xc_entry_data_php_t *next;
|
|
|
|
xc_cache_t *cache; /* which cache it's on */
|
|
|
|
|
|
|
|
xc_md5sum_t md5; /* md5sum of the source */
|
|
|
|
zend_ulong refcount; /* count of entries referencing to this data */
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
size_t sourcesize;
|
2006-12-09 16:27:03 +00:00
|
|
|
zend_ulong hits; /* hits of this php */
|
|
|
|
size_t size;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
zend_op_array *op_array;
|
|
|
|
|
2006-07-16 11:07:57 +00:00
|
|
|
#ifdef HAVE_XCACHE_CONSTANT
|
|
|
|
zend_uint constinfo_cnt;
|
|
|
|
xc_constinfo_t *constinfos;
|
|
|
|
#endif
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_uint funcinfo_cnt;
|
|
|
|
xc_funcinfo_t *funcinfos;
|
|
|
|
|
|
|
|
zend_uint classinfo_cnt;
|
|
|
|
xc_classinfo_t *classinfos;
|
2006-10-04 00:38:45 +00:00
|
|
|
zend_bool have_early_binding;
|
2006-10-29 02:05:01 +00:00
|
|
|
|
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
zend_uint autoglobal_cnt;
|
|
|
|
xc_autoglobal_t *autoglobals;
|
|
|
|
#endif
|
2006-12-09 16:27:03 +00:00
|
|
|
|
|
|
|
zend_bool have_references;
|
|
|
|
};
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ xc_entry_data_var_t */
|
|
|
|
typedef struct {
|
|
|
|
zval *value;
|
2006-12-09 16:27:03 +00:00
|
|
|
|
|
|
|
zend_bool have_references;
|
2006-05-09 10:58:38 +00:00
|
|
|
} xc_entry_data_var_t;
|
|
|
|
/* }}} */
|
|
|
|
typedef zvalue_value xc_entry_name_t;
|
|
|
|
/* {{{ xc_entry_t */
|
|
|
|
struct _xc_entry_t {
|
|
|
|
xc_entry_type_t type;
|
|
|
|
xc_hash_value_t hvalue;
|
|
|
|
xc_entry_t *next;
|
|
|
|
xc_cache_t *cache; /* which cache it's on */
|
|
|
|
|
|
|
|
size_t size;
|
2006-12-09 16:27:03 +00:00
|
|
|
zend_ulong refcount; /* count of instances holding this entry */
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_ulong hits;
|
|
|
|
time_t ctime; /* the ctime of this entry */
|
|
|
|
time_t atime; /* the atime of this entry */
|
|
|
|
time_t dtime; /* the deletion time of this entry */
|
2006-08-30 00:31:03 +00:00
|
|
|
long ttl; /* ttl of time entry, var only */
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar name_type;
|
|
|
|
#endif
|
|
|
|
xc_entry_name_t name;
|
|
|
|
|
|
|
|
union {
|
|
|
|
xc_entry_data_php_t *php;
|
|
|
|
xc_entry_data_var_t *var;
|
|
|
|
} data;
|
2006-10-10 00:46:00 +00:00
|
|
|
|
2006-12-09 16:27:03 +00:00
|
|
|
time_t mtime; /* the mtime of origin source file */
|
|
|
|
#ifdef HAVE_INODE
|
|
|
|
int device; /* the filesystem device */
|
|
|
|
int inode; /* the filesystem inode */
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
extern zend_module_entry xcache_module_entry;
|
|
|
|
#define phpext_xcache_ptr &xcache_module_entry
|
|
|
|
|
|
|
|
int xc_is_rw(const void *p);
|
|
|
|
int xc_is_ro(const void *p);
|
|
|
|
int xc_is_shm(const void *p);
|
|
|
|
|
|
|
|
#endif /* __XCACHE_H */
|