2006-05-09 10:58:38 +00:00
|
|
|
#ifndef __XCACHE_H
|
|
|
|
#define __XCACHE_H
|
|
|
|
#define XCACHE_NAME "XCache"
|
2012-06-24 03:16:05 +00:00
|
|
|
#ifndef XCACHE_VERSION
|
2012-07-24 02:17:02 +00:00
|
|
|
# define XCACHE_VERSION "3.0.0-dev"
|
2012-06-24 03:16:05 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
#define XCACHE_AUTHOR "mOo"
|
2012-04-05 12:34:10 +00:00
|
|
|
#define XCACHE_COPYRIGHT "Copyright (c) 2005-2012"
|
2006-05-09 10:58:38 +00:00
|
|
|
#define XCACHE_URL "http://xcache.lighttpd.net"
|
2008-03-15 02:02:45 +00:00
|
|
|
#define XCACHE_WIKI_URL XCACHE_URL "/wiki"
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#include <php.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2012-07-18 03:19:57 +00:00
|
|
|
#include "xcache/xc_shm.h"
|
|
|
|
#include "xcache/xc_lock.h"
|
2012-07-18 07:52:35 +00:00
|
|
|
#include "xcache/xc_compatibility.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#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 {
|
2012-06-23 04:49:59 +00:00
|
|
|
size_t bits;
|
|
|
|
size_t size;
|
|
|
|
xc_hash_value_t mask;
|
2006-05-09 10:58:38 +00:00
|
|
|
} xc_hash_t;
|
|
|
|
|
|
|
|
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;
|
2012-06-28 07:45:40 +00:00
|
|
|
zend_ulong updates;
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_ulong hits;
|
|
|
|
zend_ulong clogs;
|
|
|
|
zend_ulong ooms;
|
2007-07-14 05:06:10 +00:00
|
|
|
zend_ulong errors;
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_lock_t *lck;
|
2012-03-27 16:07:50 +00:00
|
|
|
xc_shm_t *shm; /* which shm contains us */
|
|
|
|
xc_mem_t *mem; /* which mem contains us */
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
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;
|
2008-02-17 16:49:46 +00:00
|
|
|
|
|
|
|
time_t hits_by_hour_cur_time;
|
|
|
|
zend_uint hits_by_hour_cur_slot;
|
|
|
|
zend_ulong hits_by_hour[24];
|
|
|
|
time_t hits_by_second_cur_time;
|
|
|
|
zend_uint hits_by_second_cur_slot;
|
|
|
|
zend_ulong hits_by_second[5];
|
2006-05-09 10:58:38 +00:00
|
|
|
} xc_cache_t;
|
|
|
|
/* }}} */
|
2012-03-23 16:17:34 +00:00
|
|
|
/* {{{ xc_op_array_info_detail_t */
|
|
|
|
typedef struct {
|
|
|
|
zend_uint index;
|
|
|
|
zend_uint info;
|
|
|
|
} xc_op_array_info_detail_t;
|
|
|
|
/* }}} */
|
2009-08-03 08:15:53 +00:00
|
|
|
/* {{{ xc_op_array_info_t */
|
|
|
|
typedef struct {
|
2011-04-09 11:05:07 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_4
|
|
|
|
zend_uint literalinfo_cnt;
|
2012-03-23 16:17:34 +00:00
|
|
|
xc_op_array_info_detail_t *literalinfos;
|
2011-04-09 11:05:07 +00:00
|
|
|
#else
|
2009-08-03 08:15:53 +00:00
|
|
|
zend_uint oplineinfo_cnt;
|
2012-03-23 16:17:34 +00:00
|
|
|
xc_op_array_info_detail_t *oplineinfos;
|
2011-04-09 11:05:07 +00:00
|
|
|
#endif
|
2009-08-03 08:15:53 +00:00
|
|
|
} xc_op_array_info_t;
|
|
|
|
/* }}} */
|
2006-05-09 10:58:38 +00:00
|
|
|
/* {{{ xc_classinfo_t */
|
|
|
|
typedef struct {
|
2006-05-24 12:38:55 +00:00
|
|
|
#ifdef IS_UNICODE
|
2012-03-26 09:41:19 +00:00
|
|
|
zend_uchar type;
|
2006-05-24 12:38:55 +00:00
|
|
|
#endif
|
2012-03-26 09:41:19 +00:00
|
|
|
const24_zstr key;
|
|
|
|
zend_uint key_size;
|
|
|
|
ulong h;
|
|
|
|
zend_uint methodinfo_cnt;
|
2009-08-03 08:15:53 +00:00
|
|
|
xc_op_array_info_t *methodinfos;
|
2012-03-26 09:41:19 +00:00
|
|
|
xc_cest_t cest;
|
2008-03-21 14:36:17 +00:00
|
|
|
#ifndef ZEND_COMPILE_DELAYED_BINDING
|
2012-03-26 09:41:19 +00:00
|
|
|
int oplineno;
|
2008-03-21 14:36:17 +00:00
|
|
|
#endif
|
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
|
2012-03-26 09:41:19 +00:00
|
|
|
zend_uchar type;
|
2006-07-16 11:07:57 +00:00
|
|
|
#endif
|
2012-03-26 09:41:19 +00:00
|
|
|
const24_zstr key;
|
|
|
|
zend_uint key_size;
|
|
|
|
ulong h;
|
2006-07-16 11:07:57 +00:00
|
|
|
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
|
2012-03-26 09:41:19 +00:00
|
|
|
zend_uchar type;
|
2006-05-24 12:38:55 +00:00
|
|
|
#endif
|
2012-03-26 09:41:19 +00:00
|
|
|
const24_zstr key;
|
|
|
|
zend_uint key_size;
|
|
|
|
ulong h;
|
2009-08-03 08:15:53 +00:00
|
|
|
xc_op_array_info_t op_array_info;
|
2006-05-09 10:58:38 +00:00
|
|
|
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
|
2012-03-26 09:41:19 +00:00
|
|
|
zend_uchar type;
|
2006-10-29 02:05:01 +00:00
|
|
|
#endif
|
2012-03-26 09:41:19 +00:00
|
|
|
const24_zstr key;
|
|
|
|
zend_uint key_len;
|
|
|
|
ulong h;
|
2006-10-29 02:05:01 +00:00
|
|
|
} xc_autoglobal_t;
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2012-03-25 02:51:51 +00:00
|
|
|
typedef struct {
|
|
|
|
char digest[16];
|
|
|
|
} xc_md5sum_t;
|
2008-01-04 11:38:57 +00:00
|
|
|
/* {{{ xc_compilererror_t */
|
|
|
|
typedef struct {
|
2009-07-10 04:02:07 +00:00
|
|
|
int type;
|
2008-01-04 11:38:57 +00:00
|
|
|
uint lineno;
|
|
|
|
int error_len;
|
|
|
|
char *error;
|
|
|
|
} xc_compilererror_t;
|
|
|
|
/* }}} */
|
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_entry_data_php_t *next;
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_hash_value_t hvalue;
|
2006-12-09 16:27:03 +00:00
|
|
|
|
|
|
|
xc_md5sum_t md5; /* md5sum of the source */
|
|
|
|
zend_ulong refcount; /* count of entries referencing to this data */
|
|
|
|
|
|
|
|
zend_ulong hits; /* hits of this php */
|
|
|
|
size_t size;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2009-08-03 08:15:53 +00:00
|
|
|
xc_op_array_info_t op_array_info;
|
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;
|
2008-03-21 14:36:17 +00:00
|
|
|
#ifndef ZEND_COMPILE_DELAYED_BINDING
|
2006-10-04 00:38:45 +00:00
|
|
|
zend_bool have_early_binding;
|
2008-03-21 14:36:17 +00:00
|
|
|
#endif
|
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
|
|
|
|
2008-01-04 11:38:57 +00:00
|
|
|
#ifdef E_STRICT
|
|
|
|
zend_uint compilererror_cnt;
|
|
|
|
xc_compilererror_t *compilererrors;
|
|
|
|
#endif
|
|
|
|
|
2006-12-09 16:27:03 +00:00
|
|
|
zend_bool have_references;
|
|
|
|
};
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
typedef zvalue_value xc_entry_name_t;
|
|
|
|
/* {{{ xc_entry_t */
|
|
|
|
struct _xc_entry_t {
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_t *next;
|
2012-03-27 16:07:50 +00:00
|
|
|
|
2012-03-28 08:48:20 +00:00
|
|
|
size_t size;
|
2012-03-27 16:07:50 +00:00
|
|
|
time_t ctime; /* creation ctime of this entry */
|
|
|
|
time_t atime; /* access atime of this entry */
|
|
|
|
time_t dtime; /* deletion time of this entry */
|
2006-05-09 10:58:38 +00:00
|
|
|
zend_ulong hits;
|
2012-06-23 04:49:59 +00:00
|
|
|
zend_ulong ttl;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
xc_entry_name_t name;
|
2012-03-27 16:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
xc_entry_t entry;
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_entry_data_php_t *php;
|
2006-10-10 00:46:00 +00:00
|
|
|
|
2012-03-27 16:07:50 +00:00
|
|
|
zend_ulong refcount; /* count of php instances holding this entry */
|
|
|
|
time_t file_mtime;
|
2012-03-28 16:15:21 +00:00
|
|
|
size_t file_size;
|
2012-03-27 16:07:50 +00:00
|
|
|
int file_device;
|
|
|
|
int file_inode;
|
2009-09-29 11:25:01 +00:00
|
|
|
|
|
|
|
int filepath_len;
|
2012-03-29 02:54:33 +00:00
|
|
|
ZEND_24(NOTHING, const) char *filepath;
|
2009-09-29 11:25:01 +00:00
|
|
|
int dirpath_len;
|
|
|
|
char *dirpath;
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
int ufilepath_len;
|
2012-03-27 16:07:50 +00:00
|
|
|
UChar *ufilepath;
|
2009-09-29 11:25:01 +00:00
|
|
|
int udirpath_len;
|
2012-03-27 16:07:50 +00:00
|
|
|
UChar *udirpath;
|
2009-09-29 11:25:01 +00:00
|
|
|
#endif
|
2012-03-27 16:07:50 +00:00
|
|
|
} xc_entry_php_t;
|
2012-03-28 09:15:06 +00:00
|
|
|
|
2012-03-28 08:48:20 +00:00
|
|
|
typedef struct {
|
|
|
|
xc_entry_t entry;
|
2012-03-29 09:24:40 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
zend_uchar name_type;
|
|
|
|
#endif
|
2012-03-28 08:48:20 +00:00
|
|
|
zval *value;
|
|
|
|
zend_bool have_references;
|
|
|
|
} xc_entry_var_t;
|
|
|
|
/* }}} */
|
|
|
|
typedef struct xc_entry_hash_t { /* {{{ */
|
2012-03-28 16:15:21 +00:00
|
|
|
xc_hash_value_t cacheid;
|
2012-03-28 08:48:20 +00:00
|
|
|
xc_hash_value_t entryslotid;
|
|
|
|
} xc_entry_hash_t;
|
|
|
|
/* }}} */
|
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);
|
2009-08-03 08:15:53 +00:00
|
|
|
/* {{{ xc_gc_op_array_t */
|
|
|
|
typedef struct {
|
|
|
|
#ifdef ZEND_ENGINE_2
|
|
|
|
zend_uint num_args;
|
|
|
|
zend_arg_info *arg_info;
|
|
|
|
#endif
|
|
|
|
zend_op *opcodes;
|
|
|
|
} xc_gc_op_array_t;
|
|
|
|
/* }}} */
|
|
|
|
void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC);
|
2012-03-27 16:07:50 +00:00
|
|
|
void xc_fix_op_array_info(const xc_entry_php_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#endif /* __XCACHE_H */
|