XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
4.9 KiB

  1. #ifndef __XCACHE_H
  2. #define __XCACHE_H
  3. #define XCACHE_NAME "XCache"
  4. #define XCACHE_VERSION "1.0.3"
  5. #define XCACHE_AUTHOR "mOo"
  6. #define XCACHE_COPYRIGHT "Copyright (c) 2005-2006"
  7. #define XCACHE_URL "http://xcache.lighttpd.net"
  8. #include <php.h>
  9. #include <zend_compile.h>
  10. #include <zend_API.h>
  11. #include "php_ini.h"
  12. #include "zend_hash.h"
  13. #ifdef HAVE_CONFIG_H
  14. #include <config.h>
  15. #endif
  16. #include "myshm.h"
  17. #include "mem.h"
  18. #include "lock.h"
  19. #ifndef ZEND_WIN32
  20. /* UnDefine if your filesystem doesn't support inodes */
  21. # define HAVE_INODE
  22. #endif
  23. #if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
  24. # define ZEND_ENGINE_2_1
  25. #endif
  26. #define NOTHING
  27. /* ZendEngine code Switcher */
  28. #ifndef ZEND_ENGINE_2
  29. # define ZESW(v1, v2) v1
  30. #else
  31. # define ZESW(v1, v2) v2
  32. #endif
  33. /* unicode */
  34. #ifdef IS_UNICODE
  35. # define UNISW(text, unicode) unicode
  36. #else
  37. # define UNISW(text, unicode) text
  38. #endif
  39. #define BUCKET_KEY_SIZE(b) \
  40. (UNISW( \
  41. (b)->nKeyLength, \
  42. ((b)->key.type == IS_UNICODE) \
  43. ? UBYTES(b->nKeyLength) \
  44. : b->nKeyLength \
  45. ))
  46. #define BUCKET_KEY(b) (UNISW((b)->arKey, (b)->key.u.string))
  47. #define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.u.unicode))
  48. #define BUCKET_KEY_TYPE(b) (UNISW(0, (b)->key.type))
  49. #ifdef IS_UNICODE
  50. # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key)
  51. #else
  52. # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
  53. #endif
  54. #define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
  55. #ifndef IS_UNICODE
  56. typedef char *zstr;
  57. # define ZSTR_S(s) (s)
  58. # define ZSTR_U(s) (s)
  59. # define ZSTR_V(s) (s)
  60. #else
  61. # define ZSTR_S(s) ((s)->s)
  62. # define ZSTR_U(s) ((s)->u)
  63. # define ZSTR_V(s) ((s)->v)
  64. #endif
  65. /* {{{ u hash wrapper */
  66. #ifndef IS_UNICODE
  67. # define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
  68. zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
  69. # define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
  70. zend_hash_find(ht, arKey, nKeyLength, pData)
  71. # define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
  72. add_assoc_zval_ex(arg, key, key_len, value)
  73. #endif
  74. /* }}} */
  75. #define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
  76. #define ECALLOC_ONE(x) ECALLOC_N(x, 1)
  77. typedef ulong xc_hash_value_t;
  78. typedef struct {
  79. int bits;
  80. int size;
  81. int mask;
  82. } xc_hash_t;
  83. /* the class entry type to be stored in class_table */
  84. typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
  85. /* xc_cest_t to (zend_class_entry*) */
  86. #define CestToCePtr(st) (ZESW(\
  87. &(st), \
  88. st \
  89. ) )
  90. /* ZCEP=zend class entry ptr */
  91. #define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
  92. (pce)->refcount, \
  93. &((pce)->refcount) \
  94. ))
  95. #define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
  96. typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
  97. /* {{{ xc_cache_t */
  98. typedef struct _xc_entry_t xc_entry_t;
  99. typedef struct {
  100. int cacheid;
  101. xc_hash_t *hcache; /* hash to cacheid */
  102. time_t compiling;
  103. zend_ulong misses;
  104. zend_ulong hits;
  105. zend_ulong clogs;
  106. zend_ulong ooms;
  107. xc_lock_t *lck;
  108. xc_shm_t *shm; /* to which shm contains us */
  109. xc_mem_t *mem; /* to which mem contains us */
  110. xc_entry_t **entries;
  111. int entries_count;
  112. xc_entry_t *deletes;
  113. int deletes_count;
  114. xc_hash_t *hentry; /* hash to entry */
  115. } xc_cache_t;
  116. /* }}} */
  117. /* {{{ xc_classinfo_t */
  118. typedef struct {
  119. #ifdef IS_UNICODE
  120. zend_uchar type;
  121. #endif
  122. char *key;
  123. zend_uint key_size;
  124. xc_cest_t cest;
  125. } xc_classinfo_t;
  126. /* }}} */
  127. /* {{{ xc_funcinfo_t */
  128. typedef struct {
  129. #ifdef IS_UNICODE
  130. zend_uchar type;
  131. #endif
  132. char *key;
  133. zend_uint key_size;
  134. zend_function func;
  135. } xc_funcinfo_t;
  136. /* }}} */
  137. typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
  138. /* {{{ xc_entry_data_php_t */
  139. typedef struct {
  140. size_t sourcesize;
  141. #ifdef HAVE_INODE
  142. int device; /* the filesystem device */
  143. int inode; /* the filesystem inode */
  144. #endif
  145. time_t mtime; /* the mtime of origin source file */
  146. zend_op_array *op_array;
  147. zend_uint funcinfo_cnt;
  148. xc_funcinfo_t *funcinfos;
  149. zend_uint classinfo_cnt;
  150. xc_classinfo_t *classinfos;
  151. } xc_entry_data_php_t;
  152. /* }}} */
  153. /* {{{ xc_entry_data_var_t */
  154. typedef struct {
  155. zval *value;
  156. time_t etime;
  157. } xc_entry_data_var_t;
  158. /* }}} */
  159. typedef zvalue_value xc_entry_name_t;
  160. /* {{{ xc_entry_t */
  161. struct _xc_entry_t {
  162. xc_entry_type_t type;
  163. xc_hash_value_t hvalue;
  164. xc_entry_t *next;
  165. xc_cache_t *cache; /* which cache it's on */
  166. size_t size;
  167. zend_ulong refcount;
  168. zend_ulong hits;
  169. time_t ctime; /* the ctime of this entry */
  170. time_t atime; /* the atime of this entry */
  171. time_t dtime; /* the deletion time of this entry */
  172. #ifdef IS_UNICODE
  173. zend_uchar name_type;
  174. #endif
  175. xc_entry_name_t name;
  176. union {
  177. xc_entry_data_php_t *php;
  178. xc_entry_data_var_t *var;
  179. } data;
  180. };
  181. /* }}} */
  182. extern zend_module_entry xcache_module_entry;
  183. #define phpext_xcache_ptr &xcache_module_entry
  184. int xc_is_rw(const void *p);
  185. int xc_is_ro(const void *p);
  186. int xc_is_shm(const void *p);
  187. #endif /* __XCACHE_H */