2006-05-09 10:58:38 +00:00
|
|
|
|
2006-10-01 08:59:23 +00:00
|
|
|
#if 0
|
2008-03-08 03:55:59 +00:00
|
|
|
#define XCACHE_DEBUG
|
2006-10-11 00:27:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
2006-10-10 00:31:50 +00:00
|
|
|
#define SHOW_DPRINT
|
2006-10-01 08:59:23 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
/* {{{ macros */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "ext/standard/info.h"
|
2006-05-27 06:53:32 +00:00
|
|
|
#include "ext/standard/md5.h"
|
2006-06-18 01:26:00 +00:00
|
|
|
#include "ext/standard/php_math.h"
|
2008-03-02 07:52:34 +00:00
|
|
|
#include "ext/standard/php_string.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "zend_extensions.h"
|
|
|
|
#include "SAPI.h"
|
|
|
|
|
|
|
|
#include "xcache.h"
|
2008-05-05 14:00:13 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
#include "ext/date/php_date.h"
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "optimizer.h"
|
2006-05-26 02:30:20 +00:00
|
|
|
#include "coverager.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
#include "disassembler.h"
|
|
|
|
#include "align.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "xcache_globals.h"
|
|
|
|
#include "processor.h"
|
|
|
|
#include "const_string.h"
|
|
|
|
#include "opcode_spec.h"
|
2006-12-08 16:11:19 +00:00
|
|
|
#include "utils.h"
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2009-08-03 08:15:53 +00:00
|
|
|
#ifndef ZEND_ENGINE_2_3
|
|
|
|
ZEND_API size_t zend_dirname(char *path, size_t len)
|
|
|
|
{
|
|
|
|
php_dirname(path, len);
|
|
|
|
return strlen(path);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > pentry->ctime + (pentry)->ttl)
|
2006-05-09 10:58:38 +00:00
|
|
|
#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)
|
|
|
|
#define UNLOCK(x) xc_unlock(x->lck)
|
2006-09-03 07:36:09 +00:00
|
|
|
|
|
|
|
#define ENTER_LOCK_EX(x) \
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_lock(x->lck); \
|
|
|
|
zend_try { \
|
|
|
|
do
|
2006-09-03 07:36:09 +00:00
|
|
|
#define LEAVE_LOCK_EX(x) \
|
2006-05-09 10:58:38 +00:00
|
|
|
while (0); \
|
|
|
|
} zend_catch { \
|
|
|
|
catched = 1; \
|
|
|
|
} zend_end_try(); \
|
2006-09-03 07:36:09 +00:00
|
|
|
xc_unlock(x->lck)
|
|
|
|
|
|
|
|
#define ENTER_LOCK(x) do { \
|
|
|
|
int catched = 0; \
|
|
|
|
ENTER_LOCK_EX(x)
|
|
|
|
#define LEAVE_LOCK(x) \
|
|
|
|
LEAVE_LOCK_EX(x); \
|
|
|
|
if (catched) { \
|
|
|
|
zend_bailout(); \
|
|
|
|
} \
|
2006-05-09 10:58:38 +00:00
|
|
|
} while(0)
|
2006-09-03 07:36:09 +00:00
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ globals */
|
2006-09-09 00:56:44 +00:00
|
|
|
static char *xc_shm_scheme = NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
static char *xc_mmap_path = NULL;
|
|
|
|
static char *xc_coredump_dir = NULL;
|
|
|
|
|
|
|
|
static xc_hash_t xc_php_hcache = {0};
|
|
|
|
static xc_hash_t xc_php_hentry = {0};
|
|
|
|
static xc_hash_t xc_var_hcache = {0};
|
|
|
|
static xc_hash_t xc_var_hentry = {0};
|
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
static zend_ulong xc_php_ttl = 0;
|
|
|
|
static zend_ulong xc_var_maxttl = 0;
|
|
|
|
|
|
|
|
enum { xc_deletes_gc_interval = 120 };
|
|
|
|
static zend_ulong xc_php_gc_interval = 0;
|
|
|
|
static zend_ulong xc_var_gc_interval = 0;
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* total size */
|
|
|
|
static zend_ulong xc_php_size = 0;
|
|
|
|
static zend_ulong xc_var_size = 0;
|
|
|
|
|
|
|
|
static xc_cache_t **xc_php_caches = NULL;
|
|
|
|
static xc_cache_t **xc_var_caches = NULL;
|
|
|
|
|
|
|
|
static zend_bool xc_initized = 0;
|
2008-03-02 05:43:01 +00:00
|
|
|
static time_t xc_init_time = 0;
|
|
|
|
static long unsigned xc_init_instance_id = 0;
|
|
|
|
#ifdef ZTS
|
|
|
|
static long unsigned xc_init_instance_subid = 0;
|
|
|
|
#endif
|
2007-05-31 03:48:08 +00:00
|
|
|
static zend_compile_file_t *origin_compile_file = NULL;
|
2007-05-31 03:23:20 +00:00
|
|
|
static zend_compile_file_t *old_compile_file = NULL;
|
|
|
|
static zend_llist_element *xc_llist_zend_extension = NULL;
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
static zend_bool xc_test = 0;
|
|
|
|
static zend_bool xc_readonly_protection = 0;
|
|
|
|
|
2006-09-20 00:24:42 +00:00
|
|
|
zend_bool xc_have_op_array_ctor = 0;
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
static zend_bool xc_module_gotup = 0;
|
|
|
|
static zend_bool xc_zend_extension_gotup = 0;
|
2006-11-17 17:21:46 +00:00
|
|
|
static zend_bool xc_zend_extension_faked = 0;
|
2006-05-09 10:58:38 +00:00
|
|
|
#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);
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* any function in *_dmz is only safe be called within locked(single thread) area */
|
|
|
|
|
2006-12-09 16:27:03 +00:00
|
|
|
static void xc_php_add_dmz(xc_entry_data_php_t *php) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_data_php_t **head = &(php->cache->phps[php->hvalue]);
|
|
|
|
php->next = *head;
|
|
|
|
*head = php;
|
|
|
|
php->cache->phps_count ++;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static xc_entry_data_php_t *xc_php_store_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_data_php_t *stored_php;
|
|
|
|
|
|
|
|
php->hits = 0;
|
|
|
|
php->refcount = 0;
|
|
|
|
stored_php = xc_processor_store_xc_entry_data_php_t(php TSRMLS_CC);
|
|
|
|
if (stored_php) {
|
|
|
|
xc_php_add_dmz(stored_php);
|
|
|
|
return stored_php;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
php->cache->ooms ++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static xc_entry_data_php_t *xc_php_find_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_data_php_t *p;
|
|
|
|
for (p = php->cache->phps[php->hvalue]; p; p = p->next) {
|
|
|
|
if (memcmp(php->md5, p->md5, sizeof(php->md5)) == 0) {
|
|
|
|
p->hits ++;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_php_free_dmz(xc_entry_data_php_t *php) /* {{{ */
|
|
|
|
{
|
|
|
|
php->cache->mem->handlers->free(php->cache->mem, (xc_entry_data_php_t *)php);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-12-10 08:18:09 +00:00
|
|
|
static void xc_php_addref_dmz(xc_entry_data_php_t *php) /* {{{ */
|
|
|
|
{
|
|
|
|
php->refcount ++;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_php_release_dmz(xc_entry_data_php_t *php) /* {{{ */
|
2006-12-09 16:27:03 +00:00
|
|
|
{
|
|
|
|
if (-- php->refcount == 0) {
|
|
|
|
xc_entry_data_php_t **pp = &(php->cache->phps[php->hvalue]);
|
|
|
|
xc_entry_data_php_t *p;
|
|
|
|
for (p = *pp; p; pp = &(p->next), p = p->next) {
|
|
|
|
if (memcmp(php->md5, p->md5, sizeof(php->md5)) == 0) {
|
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
|
|
|
xc_php_free_dmz(php);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
static inline int xc_entry_equal_dmz(xc_entry_t *a, xc_entry_t *b) /* {{{ */
|
|
|
|
{
|
|
|
|
/* this function isn't required but can be in dmz */
|
|
|
|
|
|
|
|
if (a->type != b->type) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (a->type) {
|
|
|
|
case XC_TYPE_PHP:
|
|
|
|
#ifdef HAVE_INODE
|
|
|
|
do {
|
2006-12-09 16:27:03 +00:00
|
|
|
if (a->inode) {
|
|
|
|
return a->inode == b->inode
|
|
|
|
&& a->device == b->device;
|
2006-09-13 12:22:57 +00:00
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
} while(0);
|
|
|
|
#endif
|
|
|
|
/* fall */
|
|
|
|
|
|
|
|
case XC_TYPE_VAR:
|
|
|
|
do {
|
|
|
|
#ifdef IS_UNICODE
|
|
|
|
if (a->name_type == IS_UNICODE) {
|
|
|
|
if (a->name.ustr.len != b->name.ustr.len) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return memcmp(a->name.ustr.val, b->name.ustr.val, (a->name.ustr.len + 1) * sizeof(UChar)) == 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} while(0);
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_t **head = &(xce->cache->entries[xce->hvalue]);
|
|
|
|
xce->next = *head;
|
|
|
|
*head = xce;
|
2006-05-27 03:05:10 +00:00
|
|
|
xce->cache->entries_count ++;
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_t *stored_xce;
|
|
|
|
|
|
|
|
xce->hits = 0;
|
|
|
|
xce->ctime = XG(request_time);
|
|
|
|
xce->atime = XG(request_time);
|
|
|
|
stored_xce = xc_processor_store_xc_entry_t(xce TSRMLS_CC);
|
|
|
|
if (stored_xce) {
|
|
|
|
xc_entry_add_dmz(stored_xce);
|
|
|
|
return stored_xce;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xce->cache->ooms ++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-12-09 16:27:03 +00:00
|
|
|
static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */
|
|
|
|
{
|
|
|
|
if (xce->type == XC_TYPE_PHP) {
|
2006-12-10 08:18:09 +00:00
|
|
|
xc_php_release_dmz(xce->data.php);
|
2006-12-09 16:27:03 +00:00
|
|
|
}
|
|
|
|
xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-06 06:41:04 +00:00
|
|
|
static void xc_entry_free_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
xce->cache->entries_count --;
|
|
|
|
if (xce->refcount == 0) {
|
2006-09-06 06:41:04 +00:00
|
|
|
xc_entry_free_real_dmz(xce);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
xce->next = xce->cache->deletes;
|
|
|
|
xce->cache->deletes = xce;
|
|
|
|
xce->dtime = XG(request_time);
|
|
|
|
xce->cache->deletes_count ++;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-05-09 10:58:38 +00:00
|
|
|
static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
2006-08-30 00:31:03 +00:00
|
|
|
xc_entry_t **pp = &(xce->cache->entries[xce->hvalue]);
|
2006-05-09 10:58:38 +00:00
|
|
|
xc_entry_t *p;
|
2006-08-30 00:31:03 +00:00
|
|
|
for (p = *pp; p; pp = &(p->next), p = p->next) {
|
2006-05-09 10:58:38 +00:00
|
|
|
if (xc_entry_equal_dmz(xce, p)) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
2006-09-06 11:14:26 +00:00
|
|
|
xc_entry_free_dmz(xce TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_t *p;
|
|
|
|
for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) {
|
|
|
|
if (xc_entry_equal_dmz(xce, p)) {
|
2009-07-05 09:42:31 +00:00
|
|
|
if (p->type == XC_TYPE_VAR || /* PHP */ (p->mtime == xce->mtime && p->data.php->sourcesize == xce->data.php->sourcesize)) {
|
2006-05-09 10:58:38 +00:00
|
|
|
p->hits ++;
|
|
|
|
p->atime = XG(request_time);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xc_entry_remove_dmz(p TSRMLS_CC);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_entry_hold_php_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("hold %s", xce->name.str.val);
|
2006-05-09 10:58:38 +00:00
|
|
|
xce->refcount ++;
|
|
|
|
xc_stack_push(&XG(php_holds)[xce->cache->cacheid], (void *)xce);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#if 0
|
|
|
|
static void xc_entry_hold_var_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xce->refcount ++;
|
|
|
|
xc_stack_push(&XG(var_holds)[xce->cache->cacheid], (void *)xce);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
2008-02-17 16:49:46 +00:00
|
|
|
static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */
|
|
|
|
{
|
|
|
|
if (val + 1 >= count) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return val + 1;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t period, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
time_t n = XG(request_time) / period;
|
|
|
|
if (*curtime != n) {
|
|
|
|
zend_uint target_slot = n % count;
|
|
|
|
if (n - *curtime > period) {
|
|
|
|
memset(counters, 0, sizeof(counters[0]) * count);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zend_uint slot;
|
|
|
|
for (slot = advance_wrapped(*curslot, count);
|
|
|
|
slot != target_slot;
|
|
|
|
slot = advance_wrapped(slot, count)) {
|
|
|
|
counters[slot] = 0;
|
|
|
|
}
|
|
|
|
counters[target_slot] = 0;
|
|
|
|
}
|
|
|
|
*curtime = n;
|
|
|
|
*curslot = target_slot;
|
|
|
|
}
|
|
|
|
counters[*curslot] ++;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_cache_hit_dmz(xc_cache_t *cache TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
cache->hits ++;
|
|
|
|
|
|
|
|
xc_counters_inc(&cache->hits_by_hour_cur_time
|
|
|
|
, &cache->hits_by_hour_cur_slot, 60 * 60
|
|
|
|
, cache->hits_by_hour
|
|
|
|
, sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0])
|
|
|
|
TSRMLS_CC);
|
|
|
|
|
|
|
|
xc_counters_inc(&cache->hits_by_second_cur_time
|
|
|
|
, &cache->hits_by_second_cur_slot
|
|
|
|
, 1
|
|
|
|
, cache->hits_by_second
|
|
|
|
, sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0])
|
|
|
|
TSRMLS_CC);
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
/* helper function that loop through each entry */
|
|
|
|
#define XC_ENTRY_APPLY_FUNC(name) int name(xc_entry_t *entry TSRMLS_DC)
|
|
|
|
typedef XC_ENTRY_APPLY_FUNC((*cache_apply_dmz_func_t));
|
|
|
|
static void xc_entry_apply_dmz(xc_cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_t *p, **pp;
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
for (i = 0, c = cache->hentry->size; i < c; i ++) {
|
|
|
|
pp = &(cache->entries[i]);
|
2006-09-06 06:41:04 +00:00
|
|
|
for (p = *pp; p; p = *pp) {
|
2006-08-30 00:31:03 +00:00
|
|
|
if (apply_func(p TSRMLS_CC)) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
|
|
|
*pp = p->next;
|
2006-09-06 11:14:26 +00:00
|
|
|
xc_entry_free_dmz(p TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pp = &(p->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#define XC_CACHE_APPLY_FUNC(name) void name(xc_cache_t *cache TSRMLS_DC)
|
|
|
|
/* call graph:
|
2006-09-02 02:08:41 +00:00
|
|
|
* xc_gc_expires_php -> xc_gc_expires_one -> xc_entry_apply_dmz -> xc_gc_expires_php_entry_dmz
|
|
|
|
* xc_gc_expires_var -> xc_gc_expires_one -> xc_entry_apply_dmz -> xc_gc_expires_var_entry_dmz
|
2006-08-30 00:31:03 +00:00
|
|
|
*/
|
2006-09-02 02:08:41 +00:00
|
|
|
static XC_ENTRY_APPLY_FUNC(xc_gc_expires_php_entry_dmz) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("ttl %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) entry->atime, xc_php_ttl);
|
2006-08-30 00:31:03 +00:00
|
|
|
if (XG(request_time) > entry->atime + xc_php_ttl) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-02 02:08:41 +00:00
|
|
|
static XC_ENTRY_APPLY_FUNC(xc_gc_expires_var_entry_dmz) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
if (VAR_ENTRY_EXPIRED(entry)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_gc_expires_one(xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval);
|
2006-09-03 06:16:02 +00:00
|
|
|
if (XG(request_time) - cache->last_gc_expires >= gc_interval) {
|
2006-08-30 00:31:03 +00:00
|
|
|
ENTER_LOCK(cache) {
|
2006-09-03 06:16:02 +00:00
|
|
|
if (XG(request_time) - cache->last_gc_expires >= gc_interval) {
|
2006-08-30 00:31:03 +00:00
|
|
|
cache->last_gc_expires = XG(request_time);
|
|
|
|
xc_entry_apply_dmz(cache, apply_func TSRMLS_CC);
|
|
|
|
}
|
|
|
|
} LEAVE_LOCK(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-02 02:08:41 +00:00
|
|
|
static void xc_gc_expires_php(TSRMLS_D) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (!xc_php_ttl || !xc_php_gc_interval || !xc_php_caches) {
|
2006-08-30 00:31:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, c = xc_php_hcache.size; i < c; i ++) {
|
2006-09-02 02:08:41 +00:00
|
|
|
xc_gc_expires_one(xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2006-09-02 02:08:41 +00:00
|
|
|
static void xc_gc_expires_var(TSRMLS_D) /* {{{ */
|
2006-08-30 00:31:03 +00:00
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (!xc_var_gc_interval || !xc_var_caches) {
|
2006-08-30 00:31:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, c = xc_var_hcache.size; i < c; i ++) {
|
2006-09-02 02:08:41 +00:00
|
|
|
xc_gc_expires_one(xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static XC_CACHE_APPLY_FUNC(xc_gc_delete_dmz) /* {{{ */
|
|
|
|
{
|
|
|
|
xc_entry_t *p, **pp;
|
|
|
|
|
|
|
|
pp = &cache->deletes;
|
2006-09-07 11:40:09 +00:00
|
|
|
for (p = *pp; p; p = *pp) {
|
2006-08-30 00:31:03 +00:00
|
|
|
if (XG(request_time) - p->dtime > 3600) {
|
|
|
|
p->refcount = 0;
|
|
|
|
/* issue warning here */
|
|
|
|
}
|
|
|
|
if (p->refcount == 0) {
|
2006-09-06 06:41:04 +00:00
|
|
|
/* unlink */
|
2006-08-30 00:31:03 +00:00
|
|
|
*pp = p->next;
|
|
|
|
cache->deletes_count --;
|
2006-09-06 06:41:04 +00:00
|
|
|
xc_entry_free_real_dmz(p);
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pp = &(p->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static XC_CACHE_APPLY_FUNC(xc_gc_deletes_one) /* {{{ */
|
|
|
|
{
|
|
|
|
if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) {
|
|
|
|
ENTER_LOCK(cache) {
|
|
|
|
if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) {
|
2006-09-06 01:40:49 +00:00
|
|
|
cache->last_gc_deletes = XG(request_time);
|
2006-08-30 00:31:03 +00:00
|
|
|
xc_gc_delete_dmz(cache TSRMLS_CC);
|
|
|
|
}
|
|
|
|
} LEAVE_LOCK(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_gc_deletes(TSRMLS_D) /* {{{ */
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (xc_php_caches) {
|
|
|
|
for (i = 0, c = xc_php_hcache.size; i < c; i ++) {
|
|
|
|
xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC);
|
|
|
|
}
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 03:55:57 +00:00
|
|
|
if (xc_var_caches) {
|
|
|
|
for (i = 0, c = xc_var_hcache.size; i < c; i ++) {
|
|
|
|
xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC);
|
|
|
|
}
|
2006-08-30 00:31:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* helper functions for user functions */
|
2006-08-31 00:23:20 +00:00
|
|
|
static void xc_fillinfo_dmz(int cachetype, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2008-02-17 16:49:46 +00:00
|
|
|
zval *blocks, *hits;
|
|
|
|
int i;
|
2006-05-09 10:58:38 +00:00
|
|
|
const xc_block_t *b;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
xc_memsize_t avail = 0;
|
|
|
|
#endif
|
|
|
|
xc_mem_t *mem = cache->mem;
|
2006-09-09 00:56:44 +00:00
|
|
|
const xc_mem_handlers_t *handlers = mem->handlers;
|
2007-04-07 03:21:34 +00:00
|
|
|
zend_ulong interval;
|
|
|
|
if (cachetype == XC_TYPE_PHP) {
|
|
|
|
interval = xc_php_ttl ? xc_php_gc_interval : 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
interval = xc_var_gc_interval;
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("slots"), cache->hentry->size);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("misses"), cache->misses);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("hits"), cache->hits);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("clogs"), cache->clogs);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("ooms"), cache->ooms);
|
2007-07-14 05:06:10 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("errors"), cache->errors);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-08-30 00:31:03 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("cached"), cache->entries_count);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("deleted"), cache->deletes_count);
|
2006-08-31 00:23:20 +00:00
|
|
|
if (interval) {
|
2007-04-07 03:21:34 +00:00
|
|
|
time_t gc = (cache->last_gc_expires + interval) - XG(request_time);
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("gc"), gc > 0 ? gc : 0);
|
2006-08-31 00:23:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
add_assoc_null_ex(return_value, ZEND_STRS("gc"));
|
|
|
|
}
|
2008-02-17 16:49:46 +00:00
|
|
|
MAKE_STD_ZVAL(hits);
|
|
|
|
array_init(hits);
|
|
|
|
for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) {
|
|
|
|
add_next_index_long(hits, (long) cache->hits_by_hour[i]);
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits);
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(hits);
|
|
|
|
array_init(hits);
|
|
|
|
for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) {
|
|
|
|
add_next_index_long(hits, (long) cache->hits_by_second[i]);
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
MAKE_STD_ZVAL(blocks);
|
|
|
|
array_init(blocks);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("size"), handlers->size(mem));
|
|
|
|
add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem));
|
2006-05-09 10:58:38 +00:00
|
|
|
add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) {
|
2006-05-09 10:58:38 +00:00
|
|
|
zval *bi;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(bi);
|
|
|
|
array_init(bi);
|
|
|
|
|
2006-09-09 00:56:44 +00:00
|
|
|
add_assoc_long_ex(bi, ZEND_STRS("size"), handlers->block_size(b));
|
|
|
|
add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b));
|
2006-05-09 10:58:38 +00:00
|
|
|
add_next_index_zval(blocks, bi);
|
|
|
|
#ifndef NDEBUG
|
2006-09-09 00:56:44 +00:00
|
|
|
avail += handlers->block_size(b);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks);
|
2008-07-04 08:38:12 +00:00
|
|
|
#ifndef NDEBUG
|
2006-09-09 00:56:44 +00:00
|
|
|
assert(avail == handlers->avail(mem));
|
2008-07-04 08:38:12 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_fillentry_dmz(xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
zval* ei;
|
|
|
|
xc_entry_data_php_t *php;
|
|
|
|
xc_entry_data_var_t *var;
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(ei);
|
|
|
|
array_init(ei);
|
|
|
|
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("refcount"), entry->refcount);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("hits"), entry->hits);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("ctime"), entry->ctime);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("atime"), entry->atime);
|
2007-03-01 10:56:22 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("hvalue"), entry->hvalue);
|
2006-09-08 13:13:59 +00:00
|
|
|
if (del) {
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
#ifdef IS_UNICODE
|
|
|
|
do {
|
|
|
|
zval *zv;
|
|
|
|
ALLOC_INIT_ZVAL(zv);
|
|
|
|
switch (entry->name_type) {
|
|
|
|
case IS_UNICODE:
|
|
|
|
ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1);
|
|
|
|
break;
|
|
|
|
case IS_STRING:
|
|
|
|
ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
zv->type = entry->name_type;
|
|
|
|
add_assoc_zval_ex(ei, ZEND_STRS("name"), zv);
|
|
|
|
} while (0);
|
|
|
|
#else
|
2006-07-31 12:11:30 +00:00
|
|
|
add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
switch (entry->type) {
|
|
|
|
case XC_TYPE_PHP:
|
|
|
|
php = entry->data.php;
|
2006-12-10 08:13:37 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size + php->size);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("phprefcount"), php->refcount);
|
2006-07-16 11:07:57 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("sourcesize"), php->sourcesize);
|
2006-05-09 10:58:38 +00:00
|
|
|
#ifdef HAVE_INODE
|
2006-12-09 16:27:03 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("device"), entry->device);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("inode"), entry->inode);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
2006-12-09 16:27:03 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("mtime"), entry->mtime);
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2006-07-16 11:07:57 +00:00
|
|
|
#ifdef HAVE_XCACHE_CONSTANT
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("constinfo_cnt"), php->constinfo_cnt);
|
|
|
|
#endif
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("function_cnt"), php->funcinfo_cnt);
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("class_cnt"), php->classinfo_cnt);
|
2006-10-29 02:05:01 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("autoglobal_cnt"),php->autoglobal_cnt);
|
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
break;
|
2006-12-10 08:13:37 +00:00
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
case XC_TYPE_VAR:
|
|
|
|
var = entry->data.var;
|
2006-12-10 08:13:37 +00:00
|
|
|
add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size);
|
2006-05-09 10:58:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_next_index_zval(list, ei);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
zval* list;
|
|
|
|
int i, c;
|
|
|
|
xc_entry_t *e;
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(list);
|
|
|
|
array_init(list);
|
|
|
|
|
|
|
|
for (i = 0, c = cache->hentry->size; i < c; i ++) {
|
|
|
|
for (e = cache->entries[i]; e; e = e->next) {
|
2006-05-24 07:52:48 +00:00
|
|
|
xc_fillentry_dmz(e, 0, list TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
add_assoc_zval(return_value, "cache_list", list);
|
|
|
|
|
|
|
|
ALLOC_INIT_ZVAL(list);
|
|
|
|
array_init(list);
|
|
|
|
for (e = cache->deletes; e; e = e->next) {
|
2006-05-24 07:52:48 +00:00
|
|
|
xc_fillentry_dmz(e, 1, list TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
add_assoc_zval(return_value, "deleted_list", list);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
|
|
|
|
{
|
|
|
|
zend_uint i;
|
|
|
|
xc_entry_data_php_t *p = xce->data.php;
|
2007-07-11 11:58:16 +00:00
|
|
|
zend_op_array *old_active_op_array = CG(active_op_array);
|
2006-05-09 10:58:38 +00:00
|
|
|
#ifndef ZEND_ENGINE_2
|
2007-12-28 12:09:43 +00:00
|
|
|
ALLOCA_FLAG(use_heap)
|
2006-05-09 10:58:38 +00:00
|
|
|
/* new ptr which is stored inside CG(class_table) */
|
2007-12-28 10:16:12 +00:00
|
|
|
xc_cest_t **new_cest_ptrs = (xc_cest_t **)my_do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt, use_heap);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
|
|
|
|
2006-10-04 00:38:45 +00:00
|
|
|
CG(active_op_array) = p->op_array;
|
|
|
|
|
2006-07-16 11:07:57 +00:00
|
|
|
#ifdef HAVE_XCACHE_CONSTANT
|
|
|
|
/* install constant */
|
|
|
|
for (i = 0; i < p->constinfo_cnt; i ++) {
|
|
|
|
xc_constinfo_t *ci = &p->constinfos[i];
|
|
|
|
xc_install_constant(xce->name.str.val, &ci->constant,
|
2008-01-05 04:45:48 +00:00
|
|
|
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
|
2006-07-16 11:07:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
/* install function */
|
|
|
|
for (i = 0; i < p->funcinfo_cnt; i ++) {
|
|
|
|
xc_funcinfo_t *fi = &p->funcinfos[i];
|
|
|
|
xc_install_function(xce->name.str.val, &fi->func,
|
2008-01-05 04:45:48 +00:00
|
|
|
UNISW(0, fi->type), fi->key, fi->key_size, fi->h TSRMLS_CC);
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* install class */
|
|
|
|
for (i = 0; i < p->classinfo_cnt; i ++) {
|
|
|
|
xc_classinfo_t *ci = &p->classinfos[i];
|
|
|
|
#ifndef ZEND_ENGINE_2
|
|
|
|
zend_class_entry *ce = CestToCePtr(ci->cest);
|
|
|
|
/* fix pointer to the be which inside class_table */
|
|
|
|
if (ce->parent) {
|
2006-10-07 04:55:05 +00:00
|
|
|
zend_uint class_idx = (/* class_num */ (int) (long) ce->parent) - 1;
|
2006-05-09 10:58:38 +00:00
|
|
|
assert(class_idx < i);
|
|
|
|
ci->cest.parent = new_cest_ptrs[class_idx];
|
|
|
|
}
|
|
|
|
new_cest_ptrs[i] =
|
|
|
|
#endif
|
2008-03-21 14:36:17 +00:00
|
|
|
#ifdef ZEND_COMPILE_DELAYED_BINDING
|
|
|
|
xc_install_class(xce->name.str.val, &ci->cest, -1,
|
|
|
|
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
|
|
|
|
#else
|
2006-10-04 00:38:45 +00:00
|
|
|
xc_install_class(xce->name.str.val, &ci->cest, ci->oplineno,
|
2008-01-05 04:45:48 +00:00
|
|
|
UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
|
2008-03-21 14:36:17 +00:00
|
|
|
#endif
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 02:05:01 +00:00
|
|
|
#ifdef ZEND_ENGINE_2_1
|
|
|
|
/* trigger auto_globals jit */
|
|
|
|
for (i = 0; i < p->autoglobal_cnt; i ++) {
|
|
|
|
xc_autoglobal_t *aginfo = &p->autoglobals[i];
|
|
|
|
/*
|
|
|
|
zend_auto_global *auto_global;
|
2008-01-05 04:45:48 +00:00
|
|
|
if (zend_u_hash_quick_find(CG(auto_globals), aginfo->type, aginfo->key, aginfo->key_len+1, aginfo->h, (void **) &auto_global)==SUCCESS) {
|
2006-10-29 02:05:01 +00:00
|
|
|
if (auto_global->armed) {
|
|
|
|
auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
zend_u_is_auto_global(aginfo->type, aginfo->key, aginfo->key_len TSRMLS_CC);
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-04 11:38:57 +00:00
|
|
|
#ifdef E_STRICT
|
|
|
|
/* restore trigger errors */
|
|
|
|
for (i = 0; i < p->compilererror_cnt; i ++) {
|
|
|
|
xc_compilererror_t *error = &p->compilererrors[i];
|
|
|
|
CG(zend_lineno) = error->lineno;
|
2009-07-10 04:02:07 +00:00
|
|
|
zend_error(error->type, "%s", error->error);
|
2008-01-04 11:38:57 +00:00
|
|
|
}
|
|
|
|
CG(zend_lineno) = 0;
|
|
|
|
#endif
|
2006-10-29 02:05:01 +00:00
|
|
|
|
2006-05-09 10:58:38 +00:00
|
|
|
i = 1;
|
|
|
|
zend_hash_add(&EG(included_files), xce->name.str.val, xce->name.str.len+1, (void *)&i, sizeof(int), NULL);
|
2006-09-03 07:37:05 +00:00
|
|
|
if (h) {
|
|
|
|
zend_llist_add_element(&CG(open_files), h);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
|
|
|
|
#ifndef ZEND_ENGINE_2
|
2007-12-28 10:16:12 +00:00
|
|
|
my_free_alloca(new_cest_ptrs, use_heap);
|
2006-05-09 10:58:38 +00:00
|
|
|
#endif
|
2007-07-11 11:58:16 +00:00
|
|
|
CG(active_op_array) = old_active_op_array;
|
2006-05-09 10:58:38 +00:00
|
|
|
return p->op_array;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2006-05-24 07:52:48 +00:00
|
|
|
static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
xc_stack_t *s;
|
|
|
|
xc_cache_t *cache;
|
|
|
|
xc_entry_t *xce;
|
|
|
|
|
|
|
|
for (i = 0; i < cachecount; i ++) {
|
|
|
|
s = &holds[i];
|
2006-12-09 03:42:09 +00:00
|
|
|
TRACE("holded %d", xc_stack_count(s));
|
|
|
|
if (xc_stack_count(s)) {
|
2006-05-09 10:58:38 +00:00
|
|
|
cache = ((xc_entry_t *)xc_stack_top(s))->cache;
|
|
|
|
ENTER_LOCK(cache) {
|
2006-12-09 03:42:09 +00:00
|
|
|
while (xc_stack_count(s)) {
|
2006-09-06 12:14:01 +00:00
|
|
|
xce = (xc_entry_t*) xc_stack_pop(s);
|
2006-12-08 16:11:19 +00:00
|
|
|
TRACE("unhold %s", xce->name.str.val);
|
2006-05-09 10:58:38 +00:00
|
|
|
xce->refcount --;
|
|
|
|
assert(xce->refcount >= 0);
|
|
|
|
}
|
|
|
|
} LEAVE_LOCK(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
static void xc_entry_unholds(TSRMLS_D) /* {{{ */
|
|
|
|
{
|
2008-01-09 03:55:57 +00:00
|
|
|
if (xc_php_caches) {
|
|
|
|
xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xc_var_caches) {
|
|
|
|
xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC);
|
|
|
|
}
|
2006-05-09 10:58:38 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
2006-05-24 07:52:48 +00:00
|
|
|
static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */
|
2006-05-09 10:58:38 +00:00
|
|
|
{
|
2006-09-13 12:22:57 +00:00
|
|
|
char filepath[MAXPATHLEN];
|
2006-05-09 10:58:38 +00:00
|
|
|
char *paths, *path;
|
|
|
|
char *tokbuf;
|
|
|
|
int size = strlen(include_path) + 1;
|
|
|
|
char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' };
|
2009-08-03 07:37:21 +00:00
|
|
|
int ret;
|
2007-12-28 10:16:12 +00:00
|
|
|
ALLOCA_FLAG(use_heap)
|
2006-05-09 10:58:38 +00:00
|
|
|
|
2007-12-28 10:16:12 +00:00
|
|
|
paths = (char *)my_do_alloca(size, use_heap);
|
2006-05-09 10:58:38 +00:00
|
|
|
memcpy(paths, include_path, size);
|
|
|
|
|
2006-05-24 07:52:48 +00:00
|
|
|
for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) {
|
2009-08-03 07:37:21 +00:00
|
|