Browse Source

refactor: split extension init to sub module. TODO: compatibility regression

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1026 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 9 years ago
parent
commit
4064549371
  1. 1
      ChangeLog
  2. 8
      Makefile.frag.deps
  3. 1
      NEWS
  4. 4
      config.m4
  5. 4
      config.w32
  6. 4
      mod_cacher/htdocs/xcache.php
  7. 204
      mod_coverager/xc_coverager.c
  8. 25
      mod_coverager/xc_coverager.h
  9. 48
      mod_disassembler/xc_disassembler.c
  10. 15
      mod_disassembler/xc_disassembler.h
  11. 94
      mod_optimizer/xc_optimizer.c
  12. 13
      mod_optimizer/xc_optimizer.h
  13. 6
      xcache-test.ini
  14. 13
      xcache-zh-gb2312.ini
  15. 438
      xcache.c
  16. 14
      xcache.ini
  17. 8
      xcache/xc_compatibility.h
  18. 104
      xcache/xc_extension.c
  19. 16
      xcache/xc_extension.h
  20. 38
      xcache/xc_ini.c
  21. 19
      xcache/xc_ini.h
  22. 3
      xcache/xc_sandbox.h

1
ChangeLog

@ -13,6 +13,7 @@ ChangeLog
* closes #972: warning/error when XCache is loaded incorrectly
* closes #73: warn for improper PHP_FCGI_CHILDREN setting fcgi mode (>=PHP_5_3)
* closes #174: updated api for clear all cache
* uses extension to load XCache. load via zend_extension is unsupported
2.0.1 2012-07-14
ChangeLog

8
Makefile.frag.deps

@ -1,15 +1,17 @@
$(XCACHE_INCLUDES_I) $(builddir)/includes.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h
$(builddir)/mod_assembler/xc_assembler.lo:
$(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h
$(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
$(builddir)/mod_decoder/xc_decoder.lo:
$(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H)
$(builddir)/mod_encoder/xc_encoder.lo:
$(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
$(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_stack.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h
$(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_stack.h
$(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h
$(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(XCACHE_PROC_H) $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_foreachcoresig.h
$(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(XCACHE_PROC_H) $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_foreachcoresig.h
$(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h
$(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h
$(builddir)/xcache/xc_extension.lo: $(srcdir)/xcache/xc_extension.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h
$(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h
$(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache/xc_lock.h
$(builddir)/xcache/xc_malloc.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h
$(builddir)/xcache/xc_mem.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h

1
NEWS

@ -3,6 +3,7 @@
* improvements
* adds warning for misconfiguration
* auto disable caching on crash
* uses extension to load XCache. load via zend_extension is unsupported
2.0.1 2012-07-14
========

4
config.m4

@ -31,8 +31,10 @@ xc_trace.c \
xcache_sources="$xcache_sources util/$i"
done
for i in \
xc_const_string.c \
xc_compatibility.c \
xc_const_string.c \
xc_extension.c \
xc_ini.c \
xc_lock.c \
xc_mem.c \
xc_opcode_spec.c \

4
config.w32

@ -18,8 +18,10 @@ xc_trace.c \
", "xcache");
ADD_SOURCES(configure_module_dirname + "/xcache", " \
xc_const_string.c \
xc_compatibility.c \
xc_const_string.c \
xc_extension.c \
xc_ini.c \
xc_lock.c \
xc_mem.c \
xc_opcode_spec.c \

4
mod_cacher/htdocs/xcache.php

@ -354,8 +354,8 @@ default:
ob_start();
phpinfo(INFO_MODULES);
$moduleinfo = ob_get_clean();
if (preg_match('!XCache</a></h2>(.*?)<h2>!is', $moduleinfo, $m)) {
$moduleinfo = $m[1];
if (preg_match_all('!XCache[^<]*</a></h2>(.*?)<h2>!is', $moduleinfo, $m)) {
$moduleinfo = implode('', $m[1]);
}
else {
$moduleinfo = null;

204
mod_coverager/xc_coverager.c

@ -2,6 +2,8 @@
#define XCACHE_DEBUG
#endif
#include "xc_coverager.h"
#include <stdio.h>
#include "xcache.h"
#include "ext/standard/flock_compat.h"
@ -12,11 +14,14 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"
#include "util/xc_trace.h"
#include "xcache_globals.h"
#include "xc_coverager.h"
#include "xcache/xc_utils.h"
#include "ext/standard/info.h"
typedef HashTable *coverager_t;
#define PCOV_HEADER_MAGIC 0x564f4350
@ -33,7 +38,7 @@ static void xc_destroy_coverage(void *pDest) /* {{{ */
efree(cov);
}
/* }}} */
void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC) /* {{{ */
static void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC) /* {{{ */
{
char *fullpath;
struct stat st;
@ -247,7 +252,7 @@ static void xc_coverager_disable(TSRMLS_D) /* {{{ */
}
/* }}} */
void xc_coverager_request_init(TSRMLS_D) /* {{{ */
static PHP_RINIT_FUNCTION(xcache_coverager) /* {{{ */
{
if (XG(coverager)) {
xc_coverager_enable(TSRMLS_C);
@ -260,6 +265,7 @@ void xc_coverager_request_init(TSRMLS_D) /* {{{ */
else {
XG(coverage_enabled) = 0;
}
return SUCCESS;
}
/* }}} */
static void xc_coverager_autodump(TSRMLS_D) /* {{{ */
@ -334,12 +340,13 @@ static void xc_coverager_dump(zval *return_value TSRMLS_DC) /* {{{ */
}
}
/* }}} */
void xc_coverager_request_shutdown(TSRMLS_D) /* {{{ */
static PHP_RSHUTDOWN_FUNCTION(xcache_coverager) /* {{{ */
{
if (XG(coverager)) {
xc_coverager_autodump(TSRMLS_C);
xc_coverager_cleanup(TSRMLS_C);
}
return SUCCESS;
}
/* }}} */
@ -456,7 +463,7 @@ static zend_op_array *xc_compile_file_for_coverage(zend_file_handle *h, int type
/* }}} */
/* hits */
void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op) /* {{{ */
static void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op) /* {{{ */
{
TSRMLS_FETCH();
@ -470,42 +477,6 @@ void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op) /* {{{
}
/* }}} */
/* MINIT/MSHUTDOWN */
int xc_coverager_module_init(int module_number TSRMLS_DC) /* {{{ */
{
old_compile_file = zend_compile_file;
zend_compile_file = xc_compile_file_for_coverage;
if (cfg_get_string("xcache.coveragedump_directory", &xc_coveragedump_dir) == SUCCESS && xc_coveragedump_dir) {
int len;
xc_coveragedump_dir = pestrdup(xc_coveragedump_dir, 1);
len = strlen(xc_coveragedump_dir);
if (len) {
if (xc_coveragedump_dir[len - 1] == '/') {
xc_coveragedump_dir[len - 1] = '\0';
}
}
if (!strlen(xc_coveragedump_dir)) {
pefree(xc_coveragedump_dir, 1);
xc_coveragedump_dir = NULL;
}
}
return SUCCESS;
}
/* }}} */
void xc_coverager_module_shutdown() /* {{{ */
{
if (old_compile_file == xc_compile_file_for_coverage) {
zend_compile_file = old_compile_file;
}
if (xc_coveragedump_dir) {
pefree(xc_coveragedump_dir, 1);
xc_coveragedump_dir = NULL;
}
}
/* }}} */
/* user api */
/* {{{ proto array xcache_coverager_decode(string data)
* decode specified data which is saved by auto dumper to array
@ -593,3 +564,152 @@ PHP_FUNCTION(xcache_coverager_get)
}
}
/* }}} */
static zend_function_entry xcache_coverager_functions[] = /* {{{ */
{
PHP_FE(xcache_coverager_decode, NULL)
PHP_FE(xcache_coverager_start, NULL)
PHP_FE(xcache_coverager_stop, NULL)
PHP_FE(xcache_coverager_get, NULL)
PHP_FE_END
};
/* }}} */
static int xc_zend_startup(zend_extension *extension) /* {{{ */
{
return SUCCESS;
}
/* }}} */
static void xc_zend_shutdown(zend_extension *extension) /* {{{ */
{
/* empty */
}
/* }}} */
static void xc_statement_handler(zend_op_array *op_array) /* {{{ */
{
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_STMT);
#endif
}
/* }}} */
static void xc_fcall_begin_handler(zend_op_array *op_array) /* {{{ */
{
#if 0
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_BEGIN);
#endif
}
/* }}} */
static void xc_fcall_end_handler(zend_op_array *op_array) /* {{{ */
{
#if 0
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_END);
#endif
}
/* }}} */
/* {{{ zend extension definition structure */
static zend_extension xc_coverager_zend_extension_entry = {
XCACHE_NAME " Coverager",
XCACHE_VERSION,
XCACHE_AUTHOR,
XCACHE_URL,
XCACHE_COPYRIGHT,
xc_zend_startup,
xc_zend_shutdown,
NULL, /* activate_func_t */
NULL, /* deactivate_func_t */
NULL, /* message_handler_func_t */
NULL, /* statement_handler_func_t */
xc_statement_handler,
xc_fcall_begin_handler,
xc_fcall_end_handler,
NULL, /* op_array_ctor_func_t */
NULL, /* op_array_dtor_func_t */
STANDARD_ZEND_EXTENSION_PROPERTIES
};
/* }}} */
/* {{{ PHP_INI */
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("xcache.coverager" , "0", PHP_INI_ALL, OnUpdateBool, coverager, zend_xcache_globals, xcache_globals)
PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_END()
/* }}} */
static PHP_MINFO_FUNCTION(xcache_coverager) /* {{{ */
{
char *covdumpdir;
php_info_print_table_start();
php_info_print_table_row(2, "XCache Coverager Version", XCACHE_VERSION);
if (cfg_get_string("xcache.coveragedump_directory", &covdumpdir) != SUCCESS || !covdumpdir[0]) {
covdumpdir = NULL;
}
php_info_print_table_row(2, "Coverage Auto Dumper", XG(coverager) && covdumpdir ? "enabled" : "disabled");
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
static PHP_MINIT_FUNCTION(xcache_coverager) /* {{{ */
{
old_compile_file = zend_compile_file;
zend_compile_file = xc_compile_file_for_coverage;
REGISTER_INI_ENTRIES();
if (cfg_get_string("xcache.coveragedump_directory", &xc_coveragedump_dir) == SUCCESS && xc_coveragedump_dir) {
int len;
xc_coveragedump_dir = pestrdup(xc_coveragedump_dir, 1);
len = strlen(xc_coveragedump_dir);
if (len) {
if (xc_coveragedump_dir[len - 1] == '/') {
xc_coveragedump_dir[len - 1] = '\0';
}
}
if (!strlen(xc_coveragedump_dir)) {
pefree(xc_coveragedump_dir, 1);
xc_coveragedump_dir = NULL;
}
}
return xcache_zend_extension_register(&xc_coverager_zend_extension_entry, 0);
}
/* }}} */
static PHP_MSHUTDOWN_FUNCTION(xcache_coverager) /* {{{ */
{
if (old_compile_file == xc_compile_file_for_coverage) {
zend_compile_file = old_compile_file;
}
if (xc_coveragedump_dir) {
pefree(xc_coveragedump_dir, 1);
xc_coveragedump_dir = NULL;
}
UNREGISTER_INI_ENTRIES();
return xcache_zend_extension_unregister(&xc_coverager_zend_extension_entry);
}
/* }}} */
static zend_module_entry xcache_coverager_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER,
XCACHE_NAME "_Coverager",
xcache_coverager_functions,
PHP_MINIT(xcache_coverager),
PHP_MSHUTDOWN(xcache_coverager),
PHP_RINIT(xcache_coverager),
PHP_RSHUTDOWN(xcache_coverager),
PHP_MINFO(xcache_coverager),
XCACHE_VERSION,
#ifdef PHP_GINIT
NO_MODULE_GLOBALS,
#endif
#ifdef ZEND_ENGINE_2
NULL,
#else
NULL,
NULL,
#endif
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
int xc_coverager_startup_module() /* {{{ */
{
return zend_startup_module(&xcache_coverager_module_entry);
}
/* }}} */

25
mod_coverager/xc_coverager.h

@ -1,17 +1,12 @@
#ifndef XC_COVERAGER_H_D5BB29AAB992B932E91C70A8C2F5D2B1
#define XC_COVERAGER_H_D5BB29AAB992B932E91C70A8C2F5D2B1
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "php.h"
#include "xcache.h"
void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op);
int xc_coverager_module_init(int module_number TSRMLS_DC);
void xc_coverager_module_shutdown();
void xc_coverager_request_init(TSRMLS_D);
void xc_coverager_request_shutdown(TSRMLS_D);
PHP_FUNCTION(xcache_coverager_decode);
PHP_FUNCTION(xcache_coverager_start);
PHP_FUNCTION(xcache_coverager_stop);
PHP_FUNCTION(xcache_coverager_get);
#define XCACHE_COVERAGER_FUNCTIONS() \
PHP_FE(xcache_coverager_decode, NULL) \
PHP_FE(xcache_coverager_start, NULL) \
PHP_FE(xcache_coverager_stop, NULL) \
PHP_FE(xcache_coverager_get, NULL)
int xc_coverager_startup_module();
#endif /* XC_COVERAGER_H_D5BB29AAB992B932E91C70A8C2F5D2B1 */

48
mod_disassembler/xc_disassembler.c

@ -2,8 +2,11 @@
#include "xcache.h"
#include "xcache/xc_utils.h"
#include "xcache/xc_sandbox.h"
#include "xcache/xc_compatibility.h"
#include "xc_processor.h"
#include "ext/standard/info.h"
static void xc_dasm(zval *output, zend_op_array *op_array TSRMLS_DC) /* {{{ */
{
const Bucket *b;
@ -215,3 +218,48 @@ PHP_FUNCTION(xcache_dasm_string)
xc_dasm_string(return_value, code TSRMLS_CC);
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION(xcache_disassembler) */
static PHP_MINFO_FUNCTION(xcache_disassembler)
{
php_info_print_table_start();
php_info_print_table_row(2, "XCache Disassembler Version", XCACHE_VERSION);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
static zend_function_entry xcache_disassembler_functions[] = /* {{{ */
{
PHP_FE(xcache_dasm_file, NULL)
PHP_FE(xcache_dasm_string, NULL)
PHP_FE_END
};
/* }}} */
static zend_module_entry xcache_disassembler_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER,
XCACHE_NAME "_Disassembler",
xcache_disassembler_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(xcache_disassembler),
XCACHE_VERSION,
#ifdef PHP_GINIT
NO_MODULE_GLOBALS,
#endif
#ifdef ZEND_ENGINE_2
NULL,
#else
NULL,
NULL,
#endif
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
int xc_disassembler_startup_module() /* {{{ */
{
return zend_startup_module(&xcache_disassembler_module_entry);
}
/* }}} */

15
mod_disassembler/xc_disassembler.h

@ -1,7 +1,10 @@
#include "php.h"
#ifndef XC_DISASSEMBLER_H_1547840703D7ADD9C19041818BE9E3C7
#define XC_DISASSEMBLER_H_1547840703D7ADD9C19041818BE9E3C7
PHP_FUNCTION(xcache_dasm_file);
PHP_FUNCTION(xcache_dasm_string);
#define XCACHE_DISASSEMBLER_FUNCTIONS() \
PHP_FE(xcache_dasm_file, NULL) \
PHP_FE(xcache_dasm_string, NULL)
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
int xc_disassembler_startup_module();
#endif /* XC_DISASSEMBLER_H_1547840703D7ADD9C19041818BE9E3C7 */

94
mod_optimizer/xc_optimizer.c

@ -2,13 +2,16 @@
# define XCACHE_DEBUG
#endif
#include "xcache/xc_utils.h"
#include "xc_optimizer.h"
/* the "vector" stack */
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"
#include "util/xc_trace.h"
#include "xcache_globals.h"
#include "ext/standard/info.h"
#ifdef XCACHE_DEBUG
#error 1
# include "xc_processor.h"
@ -606,7 +609,7 @@ static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
return 0;
}
/* }}} */
void xc_optimizer_op_array_handler(zend_op_array *op_array) /* {{{ */
static void xc_optimizer_op_array_handler(zend_op_array *op_array) /* {{{ */
{
TSRMLS_FETCH();
if (XG(optimizer)) {
@ -614,3 +617,88 @@ void xc_optimizer_op_array_handler(zend_op_array *op_array) /* {{{ */
}
}
/* }}} */
static int xc_zend_startup(zend_extension *extension) /* {{{ */
{
return SUCCESS;
}
/* }}} */
static void xc_zend_shutdown(zend_extension *extension) /* {{{ */
{
}
/* }}} */
/* {{{ zend extension definition structure */
static zend_extension xc_optimizer_zend_extension_entry = {
XCACHE_NAME " Optimizer",
XCACHE_VERSION,
XCACHE_AUTHOR,
XCACHE_URL,
XCACHE_COPYRIGHT,
xc_zend_startup,
xc_zend_shutdown,
NULL, /* activate_func_t */
NULL, /* deactivate_func_t */
NULL, /* message_handler_func_t */
xc_optimizer_op_array_handler,
NULL, /* statement_handler_func_t */
NULL, /* fcall_begin_handler_func_t */
NULL, /* fcall_end_handler_func_t */
NULL, /* op_array_ctor_func_t */
NULL, /* op_array_dtor_func_t */
STANDARD_ZEND_EXTENSION_PROPERTIES
};
/* }}} */
/* {{{ ini */
PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("xcache.optimizer", "0", PHP_INI_ALL, OnUpdateBool, optimizer, zend_xcache_globals, xcache_globals)
PHP_INI_END()
/* }}} */
static PHP_MINFO_FUNCTION(xcache_optimizer) /* {{{ */
{
php_info_print_table_start();
php_info_print_table_row(2, "XCache Optimizer Version", XCACHE_VERSION);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
static PHP_MINIT_FUNCTION(xcache_optimizer) /* {{{ */
{
REGISTER_INI_ENTRIES();
return xcache_zend_extension_register(&xc_optimizer_zend_extension_entry, 0);
}
/* }}} */
static PHP_MSHUTDOWN_FUNCTION(xcache_optimizer) /* {{{ */
{
UNREGISTER_INI_ENTRIES();
return xcache_zend_extension_unregister(&xc_optimizer_zend_extension_entry);
}
/* }}} */
static zend_module_entry xcache_optimizer_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER,
XCACHE_NAME "_Optimizer",
NULL,
PHP_MINIT(xcache_optimizer),
PHP_MSHUTDOWN(xcache_optimizer),
NULL,
NULL,
PHP_MINFO(xcache_optimizer),
XCACHE_VERSION,
#ifdef PHP_GINIT
NO_MODULE_GLOBALS,
#endif
#ifdef ZEND_ENGINE_2
NULL,
#else
NULL,
NULL,
#endif
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */
int xc_optimizer_startup_module() /* {{{ */
{
return zend_startup_module(&xcache_optimizer_module_entry);
}
/* }}} */

13
mod_optimizer/xc_optimizer.h

@ -1,5 +1,12 @@
#ifndef XC_OPTIMIZER_H_6614228F428A266C39CDAC30269D9857
#define XC_OPTIMIZER_H_6614228F428A266C39CDAC30269D9857
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "php.h"
#include "xcache.h"
void xc_optimizer_op_array_handler(zend_op_array *op_array);
#define XCACHE_OPTIMIZER_FUNCTIONS()
int xc_optimizer_startup_module();
#endif /* XC_OPTIMIZER_H_6614228F428A266C39CDAC30269D9857 */

6
xcache-test.ini

@ -2,10 +2,8 @@ memory_limit = 256M
error_reporting = E_ALL|E_STRICT
[xcache]
zend_extension_debug_ts=./modules/xcache.so
zend_extension_debug=./modules/xcache.so
zend_extension_ts=./modules/xcache.so
zend_extension=./modules/xcache.so
extension_dir="./modules/"
extension=xcache.so
xcache.cacher = On
xcache.test = 1
xcache.stat = 1

13
xcache-zh-gb2312.ini

@ -1,16 +1,9 @@
;; 本文件只是例子, 请在 php.ini 里设置以便生效
[xcache-common]
;; 警告: zend_extension* = *xcache* 必须是所有 zend_extension*=* 之中第一个出现
;; 安装成 zend extension, 路径一般是 "$extension_dir/xcache.so"
;; 不推荐使用 extension=xcache.so
;; 非 windows 例子
;; install as zend extension, normally "$extension_dir/xcache.so"
zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
;; ·Ç windows Àý×Ó:
extension = xcache.so
;; Windows 系统例子:
zend_extension_ts = c:/php/extensions/php_xcache.dll
;; 对于新版本 PHP, _ts 后缀已经移除, 请使用下面这行
zend_extension = c:/php/extensions/php_xcache.dll
; extension = php_xcache.dll
[xcache.admin]
xcache.admin.enable_auth = On

438
xcache.c

@ -14,14 +14,6 @@
#include <signal.h>
#include "php.h"
#include "ext/standard/info.h"
#include "ext/standard/md5.h"
#include "ext/standard/php_math.h"
#include "ext/standard/php_string.h"
#include "zend_extensions.h"
#include "SAPI.h"
#include "xcache.h"
#ifdef ZEND_ENGINE_2_1
#include "ext/date/php_date.h"
@ -29,22 +21,18 @@
#ifdef HAVE_XCACHE_OPTIMIZER
# include "mod_optimizer/xc_optimizer.h"
#else
# define XCACHE_OPTIMIZER_FUNCTIONS()
#endif
#ifdef HAVE_XCACHE_COVERAGER
# include "mod_coverager/xc_coverager.h"
#else
# define XCACHE_COVERAGER_FUNCTIONS()
#endif
#ifdef HAVE_XCACHE_DISASSEMBLER
# include "mod_disassembler/xc_disassembler.h"
#else
# define XCACHE_DISASSEMBLER_FUNCTIONS()
#endif
#include "xcache_globals.h"
#include "xc_processor.h"
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_const_string.h"
#include "xcache/xc_opcode_spec.h"
#include "xcache/xc_utils.h"
@ -54,6 +42,13 @@
#include "util/xc_vector.h"
#include "util/xc_trace.h"
#include "php.h"
#include "ext/standard/info.h"
#include "ext/standard/md5.h"
#include "ext/standard/php_math.h"
#include "ext/standard/php_string.h"
#include "SAPI.h"
#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > (pentry)->ctime + (time_t) (pentry)->ttl)
#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
#define LOCK(x) xc_lock((x)->lck)
@ -123,13 +118,6 @@ static zend_bool xc_readonly_protection = 0;
zend_bool xc_have_op_array_ctor = 0;
static zend_bool xc_module_gotup = 0;
static zend_bool xc_zend_extension_gotup = 0;
static zend_bool xc_zend_extension_faked = 0;
#if !COMPILE_DL_XCACHE
# define zend_extension_entry xcache_zend_extension_entry
#endif
ZEND_DLEXPORT zend_extension zend_extension_entry;
ZEND_DECLARE_MODULE_GLOBALS(xcache)
typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
@ -2526,10 +2514,6 @@ static void xc_request_init(TSRMLS_D) /* {{{ */
#else
XG(request_time) = sapi_get_request_time(TSRMLS_C);
#endif
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_request_init(TSRMLS_C);
#endif
}
/* }}} */
static void xc_request_shutdown(TSRMLS_D) /* {{{ */
@ -2543,9 +2527,6 @@ static void xc_request_shutdown(TSRMLS_D) /* {{{ */
#ifdef ZEND_ENGINE_2
zend_llist_destroy(&XG(gc_op_arrays));
#endif
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_request_shutdown(TSRMLS_C);
#endif
}
/* }}} */
/* {{{ PHP_GINIT_FUNCTION(xcache) */
@ -3358,11 +3339,9 @@ static zend_function_entry xcache_functions[] = /* {{{ */
PHP_FE(xcache_list, NULL)
PHP_FE(xcache_clear_cache, NULL)
PHP_FE(xcache_coredump, NULL)
XCACHE_OPTIMIZER_FUNCTIONS()
#ifdef HAVE_XCACHE_ASSEMBLER
PHP_FE(xcache_asm, NULL)
#endif
XCACHE_DISASSEMBLER_FUNCTIONS()
#ifdef HAVE_XCACHE_ENCODER
PHP_FE(xcache_encode, NULL)
#endif
@ -3370,7 +3349,6 @@ static zend_function_entry xcache_functions[] = /* {{{ */
PHP_FE(xcache_decode_file, NULL)
PHP_FE(xcache_decode_string, NULL)
#endif
XCACHE_COVERAGER_FUNCTIONS()
PHP_FE(xcache_get_special_value, NULL)
PHP_FE(xcache_get_type, NULL)
PHP_FE(xcache_get_op_type, NULL)
@ -3390,11 +3368,7 @@ static zend_function_entry xcache_functions[] = /* {{{ */
#ifdef HAVE_XCACHE_DPRINT
PHP_FE(xcache_dprint, NULL)
#endif
#ifdef PHP_FE_END
PHP_FE_END
#else
{NULL, NULL, NULL}
#endif
};
/* }}} */
@ -3546,107 +3520,124 @@ static void xcache_signal_handler(int sig) /* {{{ */
/* }}} */
#endif
/* {{{ PHP_INI */
static PHP_INI_MH(xc_OnUpdateDummy)
static startup_func_t xc_last_ext_startup;
static int xc_zend_startup_last(zend_extension *extension) /* {{{ */
{
zend_extension *ext = zend_get_extension(XCACHE_NAME);
if (ext) {
zend_error(E_WARNING, "Module '" XCACHE_NAME "' already loaded");
}
/* restore */
extension->startup = xc_last_ext_startup;
if (extension->startup) {
if (extension->startup(extension) != SUCCESS) {
return FAILURE;
}
}
assert(xc_llist_zend_extension);
xcache_llist_prepend(&zend_extensions, xc_llist_zend_extension);
return SUCCESS;
}
static PHP_INI_MH(xc_OnUpdateULong)
/* }}} */
static int xc_zend_startup(zend_extension *extension) /* {{{ */
{
zend_ulong *p = (zend_ulong *) mh_arg1;
if (!origin_compile_file) {
origin_compile_file = zend_compile_file;
zend_compile_file = xc_check_initial_compile_file;
}
*p = (zend_ulong) atoi(new_value);
return SUCCESS;
}
if (zend_llist_count(&zend_extensions) > 1) {
zend_llist_position lpos;
zend_extension *ext;
static PHP_INI_MH(xc_OnUpdateBool)
{
zend_bool *p = (zend_bool *)mh_arg1;
xc_llist_zend_extension = xcache_llist_get_element_by_zend_extension(&zend_extensions, XCACHE_NAME);
if (xc_llist_zend_extension != zend_extensions.head) {
zend_error(E_WARNING, "XCache failed to load itself as the first zend_extension. compatibility downgraded");
}
/* hide myself */
xcache_llist_unlink(&zend_extensions, xc_llist_zend_extension);
if (strncasecmp("on", new_value, sizeof("on"))) {
*p = (zend_bool) atoi(new_value);
}
else {
*p = (zend_bool) 1;
ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos);
assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data);
xc_last_ext_startup = ext->startup;
ext->startup = xc_zend_startup_last;
}
return SUCCESS;
}
static PHP_INI_MH(xc_OnUpdateString)
/* }}} */
static void xc_zend_shutdown(zend_extension *extension) /* {{{ */
{
char **p = (char**)mh_arg1;
if (*p) {
pefree(*p, 1);
}
*p = pemalloc(strlen(new_value) + 1, 1);
strcpy(*p, new_value);
return SUCCESS;
}
/* }}} */
/* {{{ zend extension definition structure */
static zend_extension zend_extension_entry = {
XCACHE_NAME,
XCACHE_VERSION,
XCACHE_AUTHOR,
XCACHE_URL,
XCACHE_COPYRIGHT,
xc_zend_startup,
xc_zend_shutdown,
NULL, /* activate_func_t */
NULL, /* deactivate_func_t */
NULL, /* message_handler_func_t */
NULL, /* op_array_handler_func_t */
NULL, /* statement_handler_func_t */
NULL, /* fcall_begin_handler_func_t */
NULL, /* fcall_end_handler_func_t */
NULL, /* op_array_ctor_func_t */
NULL, /* op_array_dtor_func_t */
STANDARD_ZEND_EXTENSION_PROPERTIES
};
/* }}} */
#ifndef ZEND_ENGINE_2
#define OnUpdateLong OnUpdateInt
#endif
/* {{{ PHP_INI */
#ifdef ZEND_WIN32
# define DEFAULT_PATH "xcache"
#else
# define DEFAULT_PATH "/dev/zero"
#endif
PHP_INI_BEGIN()
PHP_INI_ENTRY1 ("xcache.mmap_path", DEFAULT_PATH, PHP_INI_SYSTEM, xc_OnUpdateString, &xc_mmap_path)
PHP_INI_ENTRY1 ("xcache.coredump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_coredump_dir)
PHP_INI_ENTRY1 ("xcache.disable_on_crash", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_disable_on_crash)
PHP_INI_ENTRY1 ("xcache.test", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_test)
PHP_INI_ENTRY1 ("xcache.readonly_protection", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_readonly_protection)
PHP_INI_ENTRY1 ("xcache.mmap_path", DEFAULT_PATH, PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_mmap_path)
PHP_INI_ENTRY1 ("xcache.coredump_directory", "", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_coredump_dir)
PHP_INI_ENTRY1 ("xcache.disable_on_crash", "0", PHP_INI_SYSTEM, xcache_OnUpdateBool, &xc_disable_on_crash)
PHP_INI_ENTRY1 ("xcache.test", "0", PHP_INI_SYSTEM, xcache_OnUpdateBool, &xc_test)
PHP_INI_ENTRY1 ("xcache.readonly_protection", "0", PHP_INI_SYSTEM, xcache_OnUpdateBool, &xc_readonly_protection)
/* opcode cache */
PHP_INI_ENTRY1 ("xcache.size", "0", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.count", "1", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.slots", "8K", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.shm_scheme", "mmap", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_shm_scheme)
PHP_INI_ENTRY1 ("xcache.ttl", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_php_ttl)
PHP_INI_ENTRY1 ("xcache.gc_interval", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_php_gc_interval)
PHP_INI_ENTRY1 ("xcache.size", "0", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.count", "1", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.slots", "8K", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.shm_scheme", "mmap", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_shm_scheme)
PHP_INI_ENTRY1 ("xcache.ttl", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_php_ttl)
PHP_INI_ENTRY1 ("xcache.gc_interval", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_php_gc_interval)
/* var cache */
PHP_INI_ENTRY1 ("xcache.var_size", "0", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_count", "1", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_slots", "8K", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_maxttl", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_var_maxttl)
PHP_INI_ENTRY1 ("xcache.var_gc_interval", "120", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_var_gc_interval)
PHP_INI_ENTRY1 ("xcache.var_size", "0", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_count", "1", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_slots", "8K", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL)
PHP_INI_ENTRY1 ("xcache.var_maxttl", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_maxttl)
PHP_INI_ENTRY1 ("xcache.var_gc_interval", "120", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_gc_interval)
STD_PHP_INI_BOOLEAN("xcache.cacher", "1", PHP_INI_ALL, OnUpdateBool, cacher, zend_xcache_globals, xcache_globals)
STD_PHP_INI_BOOLEAN("xcache.stat", "1", PHP_INI_ALL, OnUpdateBool, stat, zend_xcache_globals, xcache_globals)
STD_PHP_INI_BOOLEAN("xcache.admin.enable_auth", "1", PHP_INI_SYSTEM, OnUpdateBool, auth_enabled, zend_xcache_globals, xcache_globals)
STD_PHP_INI_BOOLEAN("xcache.experimental", "0", PHP_INI_ALL, OnUpdateBool, experimental, zend_xcache_globals, xcache_globals)
#ifdef HAVE_XCACHE_OPTIMIZER
STD_PHP_INI_BOOLEAN("xcache.optimizer", "0", PHP_INI_ALL, OnUpdateBool, optimizer, zend_xcache_globals, xcache_globals)
#endif
STD_PHP_INI_ENTRY ("xcache.var_ttl", "0", PHP_INI_ALL, OnUpdateLong, var_ttl, zend_xcache_globals, xcache_globals)
#ifdef HAVE_XCACHE_COVERAGER
STD_PHP_INI_BOOLEAN("xcache.coverager" , "0", PHP_INI_ALL, OnUpdateBool, coverager, zend_xcache_globals, xcache_globals)
PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL)
#endif
PHP_INI_END()
/* }}} */
/* {{{ PHP_MINFO_FUNCTION(xcache) */
static PHP_MINFO_FUNCTION(xcache)
static PHP_MINFO_FUNCTION(xcache) /* {{{ */
{
char buf[100];
char *ptr;
int left, len;
xc_shm_scheme_t *scheme;
#ifdef HAVE_XCACHE_COVERAGER
char *covdumpdir;
#endif
php_info_print_table_start();
php_info_print_table_header(2, "XCache Support", "enabled");
php_info_print_table_row(2, "Version", XCACHE_VERSION);
php_info_print_table_row(2, "XCache Version", XCACHE_VERSION);
#ifdef XCACHE_VERSION_REVISION
php_info_print_table_row(2, "Revision", "r" XCACHE_VERSION_REVISION);
#endif
php_info_print_table_row(2, "Modules Built", XCACHE_MODULES);
php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "N/A");
php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "disabled");
#ifdef ZEND_ENGINE_2_1
ptr = php_format_date("Y-m-d H:i:s", sizeof("Y-m-d H:i:s") - 1, xc_init_time, 1 TSRMLS_CC);
php_info_print_table_row(2, "Cache Init Time", ptr);
@ -3692,105 +3683,11 @@ static PHP_MINFO_FUNCTION(xcache)
}
php_info_print_table_row(2, "Shared Memory Schemes", buf);
#ifdef HAVE_XCACHE_COVERAGER
if (cfg_get_string("xcache.coveragedump_directory", &covdumpdir) != SUCCESS || !covdumpdir[0]) {
covdumpdir = NULL;
}
php_info_print_table_row(2, "Coverage Auto Dumper", XG(coverager) && covdumpdir ? "enabled" : "disabled");
#endif
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
/* {{{ extension startup */
static void xc_zend_extension_register(zend_extension *new_extension, DL_HANDLE handle)
{
zend_extension extension;
extension = *new_extension;
extension.handle = handle;
zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
zend_llist_prepend_element(&zend_extensions, &extension);
TRACE("%s", "registered");
}
static zend_llist_element *xc_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name)
{
zend_llist_element *element;
for (element = zend_extensions.head; element; element = element->next) {
zend_extension *extension = (zend_extension *) element->data;
if (!strcmp(extension->name, extension_name)) {
return element;
}
}
return NULL;
}
static void xc_llist_prepend(zend_llist *l, zend_llist_element *element)
{
element->next = l->head;
element->prev = NULL;
if (l->head) {
l->head->prev = element;
}
else {
l->tail = element;
}
l->head = element;
++l->count;
}
static void xc_llist_unlink(zend_llist *l, zend_llist_element *element)
{
if ((element)->prev) {
(element)->prev->next = (element)->next;
}
else {
(l)->head = (element)->next;
}
if ((element)->next) {
(element)->next->prev = (element)->prev;
}
else {
(l)->tail = (element)->prev;
}
--l->count;
}
static int xc_zend_extension_startup(zend_extension *extension)
{
if (extension->startup) {
if (extension->startup(extension) != SUCCESS) {
return FAILURE;
}
}
return SUCCESS;
}
/* }}} */
static int xc_ptr_compare_func(void *p1, void *p2) /* {{{ */
{
return p1 == p2;
}
/* }}} */
static int xc_zend_remove_extension(zend_extension *extension) /* {{{ */
{
llist_dtor_func_t dtor;
assert(extension);
dtor = zend_extensions.dtor; /* avoid dtor */
zend_extensions.dtor = NULL;
zend_llist_del_element(&zend_extensions, extension, xc_ptr_compare_func);
zend_extensions.dtor = dtor;
return SUCCESS;
}
/* }}} */
static int xc_config_hash(xc_hash_t *p, char *name, char *default_value) /* {{{ */
{
size_t bits, size;
@ -3823,21 +3720,13 @@ static int xc_config_long(zend_ulong *p, char *name, char *default_value) /* {{{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION(xcache) */
static PHP_MINIT_FUNCTION(xcache)
static PHP_MINIT_FUNCTION(xcache) /* {{{ */
{
char *env;
zend_extension *ext;
zend_llist_position lpos;
xc_module_gotup = 1;
if (!xc_zend_extension_gotup) {
zend_error(E_WARNING, "XCache is designed to be loaded as zend_extension not extension");
xc_zend_extension_register(&zend_extension_entry, 0);
xc_zend_extension_startup(&zend_extension_entry);
xc_zend_extension_faked = 1;
}
xcache_zend_extension_register(&zend_extension_entry, 1);
ext = zend_get_extension("Zend Optimizer");
if (ext) {
/* zend_optimizer.optimization_level>0 is not compatible with other cacher, disabling */
@ -3917,11 +3806,16 @@ static PHP_MINIT_FUNCTION(xcache)
#endif
}
xc_sandbox_module_init(module_number TSRMLS_CC);
#ifdef HAVE_XCACHE_OPTIMIZER
xc_optimizer_startup_module();
#endif
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_module_init(module_number TSRMLS_CC);
xc_coverager_startup_module();
#endif
#ifdef HAVE_XCACHE_DISASSEMBLER
xc_disassembler_startup_module();
#endif
xc_sandbox_module_init(module_number TSRMLS_CC);
return SUCCESS;
err_init:
@ -3931,9 +3825,6 @@ err_init:
/* {{{ PHP_MSHUTDOWN_FUNCTION(xcache) */
static PHP_MSHUTDOWN_FUNCTION(xcache)
{
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_module_shutdown();
#endif
xc_sandbox_module_shutdown();
if (xc_initized) {
@ -3963,21 +3854,8 @@ static PHP_MSHUTDOWN_FUNCTION(xcache)
# endif
#endif
if (xc_zend_extension_faked) {
zend_extension *ext = zend_get_extension(XCACHE_NAME);
if (ext) {
if (ext->shutdown) {
ext->shutdown(ext);
}
xc_zend_remove_extension(ext);
}
}
xcache_zend_extension_unregister(&zend_extension_entry);
UNREGISTER_INI_ENTRIES();
xc_module_gotup = 0;
xc_zend_extension_gotup = 0;
xc_zend_extension_faked = 0;
return SUCCESS;
}
/* }}} */
@ -4004,24 +3882,19 @@ static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache)
}
/* }}} */
/* {{{ module dependencies */
#if ZEND_MODULE_API_NO >= 20050922
#ifdef STANDARD_MODULE_HEADER_EX
static zend_module_dep xcache_module_deps[] = {
ZEND_MOD_REQUIRED("standard")
ZEND_MOD_CONFLICTS("apc")
ZEND_MOD_CONFLICTS("eAccelerator")
ZEND_MOD_CONFLICTS("Turck MMCache")
#ifdef ZEND_MOD_END
ZEND_MOD_END
#else
{NULL, NULL, NULL, 0}
#endif
};
#endif
/* }}} */
/* {{{ module definition structure */
zend_module_entry xcache_module_entry = {
#if ZEND_MODULE_API_NO >= 20050922
#ifdef STANDARD_MODULE_HEADER_EX
STANDARD_MODULE_HEADER_EX,
NULL,
xcache_module_deps,
@ -4058,114 +3931,3 @@ zend_module_entry xcache_module_entry = {
ZEND_GET_MODULE(xcache)
#endif
/* }}} */
static startup_func_t xc_last_ext_startup;
static int xc_zend_startup_last(zend_extension *extension) /* {{{ */
{
zend_extension *ext = zend_get_extension(XCACHE_NAME);
if (ext) {
zend_error(E_WARNING, "Module '" XCACHE_NAME "' already loaded");
}
/* restore */
extension->startup = xc_last_ext_startup;
if (extension->startup) {
if (extension->startup(extension) != SUCCESS) {
return FAILURE;
}
}
assert(xc_llist_zend_extension);
xc_llist_prepend(&zend_extensions, xc_llist_zend_extension);
if (!xc_module_gotup) {
return zend_startup_module(&xcache_module_entry);
}
return SUCCESS;
}
/* }}} */
ZEND_DLEXPORT int xcache_zend_startup(zend_extension *extension) /* {{{ */
{
xc_zend_extension_gotup = 1;
if (!origin_compile_file) {
origin_compile_file = zend_compile_file;
zend_compile_file = xc_check_initial_compile_file;
}
if (zend_llist_count(&zend_extensions) > 1) {
zend_llist_position lpos;
zend_extension *ext;
xc_llist_zend_extension = xc_llist_get_element_by_zend_extension(&zend_extensions, XCACHE_NAME);
if (xc_llist_zend_extension != zend_extensions.head) {
zend_error(E_WARNING, "XCache must be loaded as the first zend_extension for maximum compatibility");
}
/* hide myself */
xc_llist_unlink(&zend_extensions, xc_llist_zend_extension);
ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos);
assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data);
xc_last_ext_startup = ext->startup;
ext->startup = xc_zend_startup_last;
}
else if (!xc_module_gotup) {
return zend_startup_module(&xcache_module_entry);
}
return SUCCESS;
}
/* }}} */
ZEND_DLEXPORT void xcache_zend_shutdown(zend_extension *extension) /* {{{ */
{
/* empty */
}
/* }}} */
ZEND_DLEXPORT void xcache_statement_handler(zend_op_array *op_array) /* {{{ */
{
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_STMT);
#endif
}
/* }}} */
ZEND_DLEXPORT void xcache_fcall_begin_handler(zend_op_array *op_array) /* {{{ */
{
#if 0
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_BEGIN);
#endif
}
/* }}} */
ZEND_DLEXPORT void xcache_fcall_end_handler(zend_op_array *op_array) /* {{{ */
{
#if 0
xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_END);
#endif
}
/* }}} */
/* {{{ zend extension definition structure */
ZEND_DLEXPORT zend_extension zend_extension_entry = {
XCACHE_NAME,
XCACHE_VERSION,
XCACHE_AUTHOR,
XCACHE_URL,
XCACHE_COPYRIGHT,
xcache_zend_startup,
xcache_zend_shutdown,
NULL, /* activate_func_t */
NULL, /* deactivate_func_t */
NULL, /* message_handler_func_t */
#ifdef HAVE_XCACHE_OPTIMIZER
xc_optimizer_op_array_handler,
#else
NULL, /* op_array_handler_func_t */
#endif
xcache_statement_handler,
xcache_fcall_begin_handler,
xcache_fcall_end_handler,
NULL, /* op_array_ctor_func_t */
NULL, /* op_array_dtor_func_t */
STANDARD_ZEND_EXTENSION_PROPERTIES
};
#ifndef ZEND_EXT_API
# define ZEND_EXT_API ZEND_DLEXPORT
#endif
#if COMPILE_DL_XCACHE
ZEND_EXTENSION();
#endif
/* }}} */

14
xcache.ini

@ -1,15 +1,9 @@
;; this is an example, it won't work unless properly configured into php.ini
[xcache-common]
;; WARNING: zend_extension* = *xcache* MUST be the first(above) of all zend_extension*=*
;; using extension=xcache.so is not recommended
;; non-windows example
;; update xxx accordingly
zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
;; windows example:
zend_extension_ts = c:/php/extensions/php_xcache.dll
;; for newer PHP, _ts is removed, use the following line instead
zend_extension = c:/php/extensions/php_xcache.dll
;; non-Windows example:
extension = xcache.so
;; Windows example:
; extension = php_xcache.dll
[xcache.admin]
xcache.admin.enable_auth = On

8
xcache/xc_compatibility.h

@ -227,4 +227,12 @@ long xc_atol(const char *str, int len);
#define zend_atol xc_atol
#endif
#ifndef ZEND_MOD_END
# define ZEND_MOD_END {NULL, NULL, NULL, 0}
#endif
#ifndef PHP_FE_END
# define PHP_FE_END {NULL, NULL, NULL}
#endif
#endif /* XC_COMPATIBILITY_H_54F26ED90198353558718191D5EE244C */

104
xcache/xc_extension.c

@ -0,0 +1,104 @@
#include "xc_extension.h"
#include "xcache.h"
#include "util/xc_trace.h"
int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend) /* {{{ */
{
zend_extension extension;
extension = *new_extension;
extension.handle = 0;
zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
if (prepend) {
zend_llist_prepend_element(&zend_extensions, &extension);
}
else {
zend_llist_add_element(&zend_extensions, &extension);
}
TRACE("%s", "registered");
return SUCCESS;
}
/* }}} */
static int xc_ptr_compare_func(void *p1, void *p2) /* {{{ */
{
return p1 == p2;
}
/* }}} */
static int xc_zend_extension_remove(zend_extension *extension) /* {{{ */
{
llist_dtor_func_t dtor;
assert(extension);
dtor = zend_extensions.dtor; /* avoid dtor */
zend_extensions.dtor = NULL;
zend_llist_del_element(&zend_extensions, extension, xc_ptr_compare_func);
zend_extensions.dtor = dtor;
return SUCCESS;
}
/* }}} */
int xcache_zend_extension_unregister(zend_extension *extension) /* {{{ */
{
zend_extension *ext = zend_get_extension(extension->name);
if (!ext) {
return FAILURE;
}
if (ext->shutdown) {
ext->shutdown(ext);
}
xc_zend_extension_remove(ext);
return SUCCESS;
}
/* }}} */
zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name) /* {{{ */
{
zend_llist_element *element;
for (element = zend_extensions.head; element; element = element->next) {
zend_extension *extension = (zend_extension *) element->data;
if (!strcmp(extension->name, extension_name)) {
return element;
}
}
return NULL;
}
/* }}} */
void xcache_llist_prepend(zend_llist *l, zend_llist_element *element) /* {{{ */
{
element->next = l->head;
element->prev = NULL;
if (l->head) {
l->head->prev = element;
}
else {
l->tail = element;
}
l->head = element;
++l->count;
}
/* }}} */
void xcache_llist_unlink(zend_llist *l, zend_llist_element *element) /* {{{ */
{
if ((element)->prev) {
(element)->prev->next = (element)->next;
}
else {
(l)->head = (element)->next;
}
if ((element)->next) {
(element)->next->prev = (element)->prev;
}
else {
(l)->tail = (element)->prev;
}
--l->count;
}
/* }}} */

16
xcache/xc_extension.h

@ -0,0 +1,16 @@
#ifndef XC_EXTENSION_H_9885D3A6DE7C469D13E34AF331E02BB8
#define XC_EXTENSION_H_9885D3A6DE7C469D13E34AF331E02BB8
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "zend_extensions.h"
int xcache_zend_extension_register(zend_extension *new_extension, zend_bool prepend);
int xcache_zend_extension_unregister(zend_extension *extension);
zend_llist_element *xcache_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name);
void xcache_llist_prepend(zend_llist *l, zend_llist_element *element);
void xcache_llist_unlink(zend_llist *l, zend_llist_element *element);
#endif /* XC_EXTENSION_H_9885D3A6DE7C469D13E34AF331E02BB8 */

38
xcache/xc_ini.c

@ -0,0 +1,38 @@
#include "xc_ini.h"
PHP_INI_MH(xcache_OnUpdateDummy)
{
return SUCCESS;
}
PHP_INI_MH(xcache_OnUpdateULong)
{
zend_ulong *p = (zend_ulong *) mh_arg1;
*p = (zend_ulong) atoi(new_value);
return SUCCESS;
}
PHP_INI_MH(xcache_OnUpdateBool)
{
zend_bool *p = (zend_bool *)mh_arg1;
if (strncasecmp("on", new_value, sizeof("on"))) {
*p = (zend_bool) atoi(new_value);
}
else {
*p = (zend_bool) 1;
}
return SUCCESS;
}
PHP_INI_MH(xcache_OnUpdateString)
{
char **p = (char**)mh_arg1;
if (*p) {
pefree(*p, 1);
}
*p = pemalloc(strlen(new_value) + 1, 1);
strcpy(*p, new_value);
return SUCCESS;
}

19
xcache/xc_ini.h

@ -0,0 +1,19 @@
#ifndef XC_INI_H_E208B8E597E7FAD950D249BE9C6B6F53
#define XC_INI_H_E208B8E597E7FAD950D249BE9C6B6F53
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "php.h"
#include "php_ini.h"
PHP_INI_MH(xcache_OnUpdateDummy);
<