source: trunk/xcache.h @ 456

Last change on this file since 456 was 456, checked in by moo, 7 years ago

fixed #133: add "compile failures" in XCache admin stats

  • Property svn:eol-style set to native
File size: 7.8 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[309]4#define XCACHE_VERSION    "2.0.0-dev"
[1]5#define XCACHE_AUTHOR     "mOo"
[442]6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2007"
[1]7#define XCACHE_URL        "http://xcache.lighttpd.net"
8
9#include <php.h>
10#include <zend_compile.h>
11#include <zend_API.h>
12#include "php_ini.h"
13#include "zend_hash.h"
14
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
[148]18#include "xc_shm.h"
[1]19#include "lock.h"
20
[165]21#define HAVE_INODE
[1]22#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
23#   define ZEND_ENGINE_2_1
24#endif
[78]25#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
26#   define ZEND_ENGINE_2_2
27#endif
[1]28
[19]29#define NOTHING
[1]30/* ZendEngine code Switcher */
31#ifndef ZEND_ENGINE_2
32#   define ZESW(v1, v2) v1
33#else
34#   define ZESW(v1, v2) v2
35#endif
36
[263]37/* {{{ dirty fix for PHP 6 */
38#ifdef add_assoc_long_ex
39static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
40{
41    add_assoc_long_ex(arg, key, key_len, value);
42}
43#   undef add_assoc_long_ex
44#   define add_assoc_long_ex my_add_assoc_long_ex
45#endif
46#ifdef add_assoc_bool_ex
47static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
48{
49    add_assoc_bool_ex(arg, key, key_len, value);
50}
51#   undef add_assoc_bool_ex
52#   define add_assoc_bool_ex my_add_assoc_bool_ex
53#endif
54#ifdef add_assoc_null_ex
55static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
56{
57    add_assoc_null_ex(arg, key, key_len);
58}
59#   undef add_assoc_null_ex
60#   define add_assoc_null_ex my_add_assoc_null_ex
61#endif
62/* }}} */
63
[1]64/* unicode */
65#ifdef IS_UNICODE
66#   define UNISW(text, unicode) unicode
67#else
68#   define UNISW(text, unicode) text
69#endif
70#define BUCKET_KEY_SIZE(b) \
71        (UNISW( \
72            (b)->nKeyLength, \
73                ((b)->key.type == IS_UNICODE) \
74                ? UBYTES(b->nKeyLength) \
75                : b->nKeyLength \
76                ))
[200]77#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
78#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
79#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
[2]80#ifdef IS_UNICODE
[104]81#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]82#else
[11]83#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]84#endif
[1]85#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
86
87#ifndef IS_UNICODE
88typedef char *zstr;
[103]89#   define ZSTR_S(s)     (s)
90#   define ZSTR_U(s)     (s)
91#   define ZSTR_V(s)     (s)
92#   define ZSTR_PS(s)    (s)
93#   define ZSTR_PU(s)    (s)
94#   define ZSTR_PV(s)    (s)
[1]95#else
[103]96#   define ZSTR_S(zs)    ((zs).s)
97#   define ZSTR_U(zs)    ((zs).u)
98#   define ZSTR_V(zs)    ((zs).v)
99#   define ZSTR_PS(pzs)  ((pzs)->s)
100#   define ZSTR_PU(pzs)  ((pzs)->u)
101#   define ZSTR_PV(pzs)  ((pzs)->v)
[1]102#endif
103
[103]104#ifndef ZSTR
105#   define ZSTR(s)      (s)
106#endif
107
108#ifndef Z_UNIVAL
109#   define Z_UNIVAL(zval) (zval).value.str.val
110#   define Z_UNILEN(zval) (zval).value.str.len
111#endif
112
[1]113/* {{{ u hash wrapper */
114#ifndef IS_UNICODE
115#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
116       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
117
[88]118#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
119       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
120
[1]121#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
122       zend_hash_find(ht, arKey, nKeyLength, pData)
123
[200]124#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
125       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
126
[1]127#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
128        add_assoc_zval_ex(arg, key, key_len, value)
129
[268]130#   define zend_u_is_auto_global(type, name, name_len) \
131        zend_is_auto_global(name, name_len)
[1]132#endif
133/* }}} */
134
135
136#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
137#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
138
139
140
141typedef ulong xc_hash_value_t;
142typedef struct {
143    int bits;
144    int size;
145    int mask;
146} xc_hash_t;
147
148/* the class entry type to be stored in class_table */
149typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
150
151/* xc_cest_t to (zend_class_entry*) */
152#define CestToCePtr(st) (ZESW(\
153            &(st), \
154            st \
155            ) )
156
157/* ZCEP=zend class entry ptr */
158#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
159            (pce)->refcount, \
160            &((pce)->refcount) \
161            ))
162
163#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
164
165typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
166
[311]167typedef struct _xc_entry_t xc_entry_t;
168typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
[1]169/* {{{ xc_cache_t */
[11]170typedef struct {
[1]171    int cacheid;
172    xc_hash_t  *hcache; /* hash to cacheid */
173
[11]174    time_t     compiling;
[1]175    zend_ulong misses;
176    zend_ulong hits;
177    zend_ulong clogs;
178    zend_ulong ooms;
[456]179    zend_ulong errors;
[1]180    xc_lock_t  *lck;
181    xc_shm_t   *shm; /* to which shm contains us */
182    xc_mem_t   *mem; /* to which mem contains us */
183
184    xc_entry_t **entries;
[32]185    int entries_count;
[311]186    xc_entry_data_php_t **phps;
187    int phps_count;
[1]188    xc_entry_t *deletes;
[32]189    int deletes_count;
[311]190    xc_hash_t  *hentry; /* hash settings to entry */
191    xc_hash_t  *hphp;   /* hash settings to php */
[114]192
193    time_t     last_gc_deletes;
194    time_t     last_gc_expires;
[1]195} xc_cache_t;
196/* }}} */
197/* {{{ xc_classinfo_t */
198typedef struct {
[14]199#ifdef IS_UNICODE
200    zend_uchar type;
201#endif
[103]202    zstr      key;
[1]203    zend_uint key_size;
204    xc_cest_t cest;
[212]205    int       oplineno;
[1]206} xc_classinfo_t;
207/* }}} */
[95]208#ifdef HAVE_XCACHE_CONSTANT
209/* {{{ xc_constinfo_t */
210typedef struct {
211#ifdef IS_UNICODE
212    zend_uchar type;
213#endif
[103]214    zstr      key;
[95]215    zend_uint key_size;
216    zend_constant constant;
217} xc_constinfo_t;
218/* }}} */
219#endif
[1]220/* {{{ xc_funcinfo_t */
221typedef struct {
[14]222#ifdef IS_UNICODE
223    zend_uchar type;
224#endif
[103]225    zstr      key;
[1]226    zend_uint key_size;
227    zend_function func;
228} xc_funcinfo_t;
229/* }}} */
[268]230#ifdef ZEND_ENGINE_2_1
231/* {{{ xc_autoglobal_t */
232typedef struct {
233#ifdef IS_UNICODE
234    zend_uchar type;
235#endif
236    zstr       key;
237    zend_uint  key_len;
238} xc_autoglobal_t;
239/* }}} */
240#endif
[1]241typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
[311]242typedef char xc_md5sum_t[16];
[1]243/* {{{ xc_entry_data_php_t */
[311]244struct _xc_entry_data_php_t {
245    xc_hash_value_t hvalue; /* hash of md5 */
246    xc_entry_data_php_t *next;
247    xc_cache_t *cache;      /* which cache it's on */
248
249    xc_md5sum_t md5;        /* md5sum of the source */
250    zend_ulong  refcount;   /* count of entries referencing to this data */
251
[1]252    size_t sourcesize;
[311]253    zend_ulong hits;        /* hits of this php */
254    size_t     size;
[1]255
256    zend_op_array *op_array;
257
[95]258#ifdef HAVE_XCACHE_CONSTANT
259    zend_uint constinfo_cnt;
260    xc_constinfo_t *constinfos;
261#endif
262
[1]263    zend_uint funcinfo_cnt;
264    xc_funcinfo_t *funcinfos;
265
266    zend_uint classinfo_cnt;
267    xc_classinfo_t *classinfos;
[212]268    zend_bool have_early_binding;
[268]269
270#ifdef ZEND_ENGINE_2_1
271    zend_uint autoglobal_cnt;
272    xc_autoglobal_t *autoglobals;
273#endif
[311]274
275    zend_bool  have_references;
276};
[1]277/* }}} */
278/* {{{ xc_entry_data_var_t */
279typedef struct {
280    zval   *value;
[311]281
282    zend_bool  have_references;
[1]283} xc_entry_data_var_t;
284/* }}} */
285typedef zvalue_value xc_entry_name_t;
286/* {{{ xc_entry_t */
287struct _xc_entry_t {
288    xc_entry_type_t type;
289    xc_hash_value_t hvalue;
290    xc_entry_t *next;
291    xc_cache_t *cache;      /* which cache it's on */
292
293    size_t     size;
[311]294    zend_ulong refcount;    /* count of instances holding this entry */
[1]295    zend_ulong hits;
296    time_t     ctime;           /* the ctime of this entry */
297    time_t     atime;           /* the atime of this entry */
298    time_t     dtime;           /* the deletion time of this entry */
[114]299    long       ttl;             /* ttl of time entry, var only */
[1]300
301#ifdef IS_UNICODE
302    zend_uchar name_type;
303#endif
304    xc_entry_name_t name;
305
306    union {
307        xc_entry_data_php_t *php;
308        xc_entry_data_var_t *var;
309    } data;
[233]310
[311]311    time_t mtime;           /* the mtime of origin source file */
312#ifdef HAVE_INODE
313    int device;             /* the filesystem device */
314    int inode;              /* the filesystem inode */
315#endif
[1]316};
317/* }}} */
318
319extern zend_module_entry xcache_module_entry;
320#define phpext_xcache_ptr &xcache_module_entry
321
322int xc_is_rw(const void *p);
323int xc_is_ro(const void *p);
324int xc_is_shm(const void *p);
325
326#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.