diff options
author | Dmitry Stogov <dmitry@zend.com> | 2018-04-28 01:20:49 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2018-04-28 01:20:49 +0300 |
commit | 83f98f7340da683a9510c1cafe56844bed705988 (patch) | |
tree | eddffe208b91eab8a802e2eea28604eab8501520 | |
parent | f75b8a44cc078045b4e4a0a7dfe7e3ad3a8176e0 (diff) | |
download | php-git-83f98f7340da683a9510c1cafe56844bed705988.tar.gz |
Don't store values of PHP_SAPI and PHP_BINARY in file cache, because it may be used by different SAPI.
-rw-r--r-- | Zend/zend_compile.c | 4 | ||||
-rw-r--r-- | Zend/zend_compile.h | 3 | ||||
-rw-r--r-- | Zend/zend_constants.h | 1 | ||||
-rw-r--r-- | ext/opcache/Optimizer/block_pass.c | 4 | ||||
-rw-r--r-- | ext/opcache/ZendAccelerator.c | 20 | ||||
-rw-r--r-- | main/main.c | 6 |
6 files changed, 33 insertions, 5 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 3517bc188f..448856dd92 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1376,7 +1376,9 @@ static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool i /* Substitute case-sensitive (or lowercase) constants */ c = zend_hash_find_ptr(EG(zend_constants), name); if (c && ( - ((c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION)) + ((c->flags & CONST_PERSISTENT) + && !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION) + && (!(c->flags & CONST_NO_FILE_CACHE) || !(CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE))) || (Z_TYPE(c->value) < IS_OBJECT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) )) { ZVAL_COPY_OR_DUP(zv, &c->value); diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index d6d816b945..623f37eac5 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -1014,6 +1014,9 @@ END_EXTERN_C() /* disable builtin special case function calls */ #define ZEND_COMPILE_NO_BUILTINS (1<<10) +/* result of compilation may be stored in file cache */ +#define ZEND_COMPILE_WITH_FILE_CACHE (1<<11) + /* The default value for CG(compiler_options) */ #define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY diff --git a/Zend/zend_constants.h b/Zend/zend_constants.h index 0b54fd715b..98484debe2 100644 --- a/Zend/zend_constants.h +++ b/Zend/zend_constants.h @@ -27,6 +27,7 @@ #define CONST_CS (1<<0) /* Case Sensitive */ #define CONST_PERSISTENT (1<<1) /* Persistent */ #define CONST_CT_SUBST (1<<2) /* Allow compile-time substitution */ +#define CONST_NO_FILE_CACHE (1<<3) /* Can't be saved in file cache */ #define PHP_USER_CONSTANT INT_MAX /* a constant defined in user space */ diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index 7a494ae5a1..d2db5181dd 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -54,7 +54,9 @@ int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int } if (retval) { - if (c->flags & CONST_PERSISTENT) { + if ((c->flags & CONST_PERSISTENT) + && (!(c->flags & CONST_NO_FILE_CACHE) + || !(CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE))) { ZVAL_COPY_VALUE(result, &c->value); if (copy) { Z_TRY_ADDREF_P(result); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 20189b160d..c70f55ec27 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1393,14 +1393,20 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script *new_persistent_script, int *from_shared_memory) { + uint32_t orig_compiler_options; + /* Check if script may be stored in shared memory */ if (!zend_accel_script_persistable(new_persistent_script)) { return new_persistent_script; } + orig_compiler_options = CG(compiler_options); + CG(compiler_options) |= ZEND_COMPILE_WITH_FILE_CACHE; if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) { + CG(compiler_options) = orig_compiler_options; return new_persistent_script; } + CG(compiler_options) = orig_compiler_options; *from_shared_memory = 1; return store_script_in_file_cache(new_persistent_script); @@ -1411,15 +1417,24 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr { zend_accel_hash_entry *bucket; uint32_t memory_used; + uint32_t orig_compiler_options; /* Check if script may be stored in shared memory */ if (!zend_accel_script_persistable(new_persistent_script)) { return new_persistent_script; } + orig_compiler_options = CG(compiler_options); +#ifdef HAVE_OPCACHE_FILE_CACHE + if (ZCG(accel_directives).file_cache) { + CG(compiler_options) |= ZEND_COMPILE_WITH_FILE_CACHE; + } +#endif if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) { + CG(compiler_options) = orig_compiler_options; return new_persistent_script; } + CG(compiler_options) = orig_compiler_options; /* exclusive lock */ zend_shared_alloc_lock(); @@ -1691,6 +1706,11 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl CG(compiler_options) |= ZEND_COMPILE_IGNORE_INTERNAL_CLASSES; CG(compiler_options) |= ZEND_COMPILE_DELAYED_BINDING; CG(compiler_options) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION; +#ifdef HAVE_OPCACHE_FILE_CACHE + if (ZCG(accel_directives).file_cache) { + CG(compiler_options) |= ZEND_COMPILE_WITH_FILE_CACHE; + } +#endif op_array = *op_array_p = accelerator_orig_compile_file(file_handle, type); CG(compiler_options) = orig_compiler_options; } zend_catch { diff --git a/main/main.c b/main/main.c index 42f34ee262..2e11aa208c 100644 --- a/main/main.c +++ b/main/main.c @@ -2051,7 +2051,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS_FAMILY", PHP_OS_FAMILY, sizeof(PHP_OS_FAMILY)-1, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS); REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS); @@ -2095,9 +2095,9 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod php_binary_init(); if (PG(php_binary)) { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); } else { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE); } php_output_register_constants(); |