mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Turn system_id into a true global
The system_id is identical for all threads and can be computed during module startup, so there is no need to calculate and store it for each thread.
This commit is contained in:
parent
c2c33aaaaa
commit
04a6aac59b
@ -109,6 +109,7 @@ ZEND_TSRMLS_CACHE_DEFINE()
|
||||
zend_accel_shared_globals *accel_shared_globals = NULL;
|
||||
|
||||
/* true globals, no need for thread safety */
|
||||
char accel_system_id[32];
|
||||
zend_bool accel_startup_ok = 0;
|
||||
static char *zps_failure_reason = NULL;
|
||||
char *zps_api_failure_reason = NULL;
|
||||
@ -2584,9 +2585,6 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
|
||||
ZEND_TSRMLS_CACHE_UPDATE();
|
||||
#endif
|
||||
memset(accel_globals, 0, sizeof(zend_accel_globals));
|
||||
|
||||
/* TODO refactor to init this just once. */
|
||||
accel_gen_system_id();
|
||||
}
|
||||
|
||||
#define ZEND_BIN_ID "BIN_" ZEND_TOSTR(SIZEOF_INT) ZEND_TOSTR(SIZEOF_LONG) ZEND_TOSTR(SIZEOF_SIZE_T) ZEND_TOSTR(SIZEOF_ZEND_LONG) ZEND_TOSTR(ZEND_MM_ALIGNMENT)
|
||||
@ -2595,7 +2593,7 @@ static void accel_gen_system_id(void)
|
||||
{
|
||||
PHP_MD5_CTX context;
|
||||
unsigned char digest[16], c;
|
||||
char *md5str = ZCG(system_id);
|
||||
char *md5str = accel_system_id;
|
||||
int i;
|
||||
|
||||
PHP_MD5Init(&context);
|
||||
@ -2795,14 +2793,14 @@ static int accel_startup(zend_extension *extension)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
accel_gen_system_id();
|
||||
|
||||
if (start_accel_module() == FAILURE) {
|
||||
accel_startup_ok = 0;
|
||||
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME ": module registration failed!");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
accel_gen_system_id();
|
||||
|
||||
#ifdef HAVE_HUGE_CODE_PAGES
|
||||
if (ZCG(accel_directives).huge_code_pages &&
|
||||
(strcmp(sapi_module.name, "cli") == 0 ||
|
||||
|
@ -206,7 +206,6 @@ typedef struct _zend_accel_globals {
|
||||
int auto_globals_mask;
|
||||
time_t request_time;
|
||||
time_t last_restart_time; /* used to synchronize SHM and in-process caches */
|
||||
char system_id[32];
|
||||
HashTable xlat_table;
|
||||
#ifndef ZEND_WIN32
|
||||
zend_ulong root_hash;
|
||||
@ -270,6 +269,7 @@ typedef struct _zend_accel_shared_globals {
|
||||
zend_string_table interned_strings;
|
||||
} zend_accel_shared_globals;
|
||||
|
||||
extern char accel_system_id[32];
|
||||
extern zend_bool accel_startup_ok;
|
||||
extern zend_bool file_cache_only;
|
||||
#if ENABLE_FILE_CACHE_FALLBACK
|
||||
|
@ -74,7 +74,7 @@ static char *create_name_with_username(char *name)
|
||||
if (!uname) {
|
||||
return NULL;
|
||||
}
|
||||
snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, ZCG(system_id));
|
||||
snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, accel_system_id);
|
||||
|
||||
free(uname);
|
||||
|
||||
@ -96,7 +96,7 @@ static char *get_mmap_base_file(void)
|
||||
if ('\\' == windir[l-1]) {
|
||||
l--;
|
||||
}
|
||||
snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, ZCG(system_id));
|
||||
snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, accel_system_id);
|
||||
|
||||
free(uname);
|
||||
|
||||
|
@ -798,7 +798,7 @@ static void zend_file_cache_serialize(zend_persistent_script *script,
|
||||
zend_persistent_script *new_script;
|
||||
|
||||
memcpy(info->magic, "OPCACHE", 8);
|
||||
memcpy(info->system_id, ZCG(system_id), 32);
|
||||
memcpy(info->system_id, accel_system_id, 32);
|
||||
info->mem_size = script->size;
|
||||
info->str_size = 0;
|
||||
info->script_offset = (char*)script - (char*)script->mem;
|
||||
@ -827,7 +827,7 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
|
||||
filename = emalloc(len + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX));
|
||||
memcpy(filename, ZCG(accel_directives).file_cache, len);
|
||||
filename[len] = '/';
|
||||
memcpy(filename + len + 1, ZCG(system_id), 32);
|
||||
memcpy(filename + len + 1, accel_system_id, 32);
|
||||
memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path));
|
||||
memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX));
|
||||
#else
|
||||
@ -859,7 +859,7 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
|
||||
len += 32;
|
||||
filename[len] = '\\';
|
||||
|
||||
memcpy(filename + len + 1, ZCG(system_id), 32);
|
||||
memcpy(filename + len + 1, accel_system_id, 32);
|
||||
|
||||
if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5] && '/' == ZSTR_VAL(script_path)[6]) {
|
||||
/* phar:// or file:// */
|
||||
@ -1550,7 +1550,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
|
||||
efree(filename);
|
||||
return NULL;
|
||||
}
|
||||
if (memcmp(info.system_id, ZCG(system_id), 32) != 0) {
|
||||
if (memcmp(info.system_id, accel_system_id, 32) != 0) {
|
||||
zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot read from file '%s' (wrong \"system_id\")\n", filename);
|
||||
zend_file_cache_flock(fd, LOCK_UN);
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user