diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-07-17 19:52:49 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-07-17 19:52:49 +0200 |
commit | 54401001a8afe42dd56a38bdc57ef5a49e6f4ab5 (patch) | |
tree | 7a375a6456b78d7b00dca1dac18dea3e345c77ee | |
parent | 6d00cff36fad3c318799dcaf527d0bea5afd2217 (diff) | |
parent | e2ed7e6716f9564fcd8b13b823519baaa7256662 (diff) | |
download | php-git-54401001a8afe42dd56a38bdc57ef5a49e6f4ab5.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
Allow multiple cache instances per user/host on Windows
-rw-r--r-- | .appveyor.yml | 2 | ||||
-rw-r--r-- | ext/opcache/ZendAccelerator.c | 45 | ||||
-rw-r--r-- | ext/opcache/ZendAccelerator.h | 6 | ||||
-rw-r--r-- | ext/opcache/shared_alloc_win32.c | 23 | ||||
-rw-r--r-- | ext/opcache/zend_accelerator_module.c | 6 | ||||
-rw-r--r-- | ext/opcache/zend_file_cache.c | 21 | ||||
-rw-r--r-- | php.ini-development | 4 | ||||
-rw-r--r-- | php.ini-production | 4 | ||||
-rwxr-xr-x | run-tests.php | 2 |
9 files changed, 62 insertions, 51 deletions
diff --git a/.appveyor.yml b/.appveyor.yml index 909a9ad65a..ab888c3493 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -33,7 +33,7 @@ environment: PARALLEL: -j2 - THREAD_SAFE: 1 OPCACHE: 1 - PARALLEL: + PARALLEL: -j2 INTRINSICS: AVX services: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 22917f2641..a7cce2e8d9 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -45,6 +45,7 @@ #include "zend_file_cache.h" #include "ext/pcre/php_pcre.h" #include "ext/standard/md5.h" +#include "ext/hash/php_hash.h" #ifdef HAVE_JIT # include "jit/zend_jit.h" @@ -58,6 +59,7 @@ typedef int uid_t; typedef int gid_t; #include <io.h> +#include <lmcons.h> #endif #ifndef ZEND_WIN32 @@ -101,6 +103,9 @@ zend_accel_shared_globals *accel_shared_globals = NULL; /* true globals, no need for thread safety */ char accel_system_id[32]; +#ifdef ZEND_WIN32 +char accel_uname_id[32]; +#endif zend_bool accel_startup_ok = 0; static char *zps_failure_reason = NULL; char *zps_api_failure_reason = NULL; @@ -2171,6 +2176,26 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) return zend_accel_load_script(persistent_script, from_shared_memory); } +#ifdef ZEND_WIN32 +static int accel_gen_uname_id(void) +{ + PHP_MD5_CTX ctx; + unsigned char digest[16]; + wchar_t uname[UNLEN + 1]; + DWORD unsize = UNLEN; + + if (!GetUserNameW(uname, &unsize)) { + return FAILURE; + } + PHP_MD5Init(&ctx); + PHP_MD5Update(&ctx, (void *) uname, (unsize - 1) * sizeof(wchar_t)); + PHP_MD5Update(&ctx, ZCG(accel_directives).cache_id, strlen(ZCG(accel_directives).cache_id)); + PHP_MD5Final(digest, &ctx); + php_hash_bin2hex(accel_uname_id, digest, sizeof digest); + return SUCCESS; +} +#endif + /* zend_stream_open_function() replacement for PHP 5.3 and above */ static int persistent_stream_open_function(const char *filename, zend_file_handle *handle) { @@ -2612,9 +2637,7 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals) static void accel_gen_system_id(void) { PHP_MD5_CTX context; - unsigned char digest[16], c; - char *md5str = accel_system_id; - int i; + unsigned char digest[16]; PHP_MD5Init(&context); PHP_MD5Update(&context, PHP_VERSION, sizeof(PHP_VERSION)-1); @@ -2626,14 +2649,7 @@ static void accel_gen_system_id(void) PHP_MD5Update(&context, __TIME__, sizeof(__TIME__)-1); } PHP_MD5Final(digest, &context); - for (i = 0; i < 16; i++) { - c = digest[i] >> 4; - c = (c <= 9) ? c + '0' : c - 10 + 'a'; - md5str[i * 2] = c; - c = digest[i] & 0x0f; - c = (c <= 9) ? c + '0' : c - 10 + 'a'; - md5str[(i * 2) + 1] = c; - } + php_hash_bin2hex(accel_system_id, digest, sizeof digest); } #ifdef HAVE_HUGE_CODE_PAGES @@ -2824,6 +2840,13 @@ static int accel_startup(zend_extension *extension) return FAILURE; } +#ifdef ZEND_WIN32 + if (UNEXPECTED(accel_gen_uname_id() == FAILURE)) { + zps_startup_failure("Unable to get user name", NULL, accelerator_remove_cb); + return SUCCESS; + } +#endif + #ifdef HAVE_HUGE_CODE_PAGES if (ZCG(accel_directives).huge_code_pages && (strcmp(sapi_module.name, "cli") == 0 || diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index ae59a3d283..0f31c65182 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -185,6 +185,9 @@ typedef struct _zend_accel_directives { zend_bool huge_code_pages; #endif char *preload; +#ifdef ZEND_WIN32 + char *cache_id; +#endif #ifdef HAVE_JIT zend_long jit; zend_long jit_buffer_size; @@ -278,6 +281,9 @@ typedef struct _zend_accel_shared_globals { } zend_accel_shared_globals; extern char accel_system_id[32]; +#ifdef ZEND_WIN32 +extern char accel_uname_id[32]; +#endif extern zend_bool accel_startup_ok; extern zend_bool file_cache_only; #if ENABLE_FILE_CACHE_FALLBACK diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c index 4cf973326a..c172f17273 100644 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@ -19,6 +19,7 @@ +----------------------------------------------------------------------+ */ +#include "php.h" #include "ZendAccelerator.h" #include "zend_shared_alloc.h" #include "zend_accelerator_util_funcs.h" @@ -67,38 +68,24 @@ static void zend_win_error_message(int type, char *msg, int err) static char *create_name_with_username(char *name) { - static char newname[MAXPATHLEN + UNLEN + 4 + 1 + 32]; - char *uname; - - uname = php_win32_get_username(); - if (!uname) { - return NULL; - } - snprintf(newname, sizeof(newname) - 1, "%s@%s@%.32s", name, uname, accel_system_id); - - free(uname); + static char newname[MAXPATHLEN + 32 + 4 + 1 + 32]; + snprintf(newname, sizeof(newname) - 1, "%s@%.32s@%.32s", name, accel_uname_id, accel_system_id); return newname; } static char *get_mmap_base_file(void) { - static char windir[MAXPATHLEN+UNLEN + 3 + sizeof("\\\\@") + 1 + 32]; - char *uname; + static char windir[MAXPATHLEN+ 32 + 3 + sizeof("\\\\@") + 1 + 32]; int l; - uname = php_win32_get_username(); - if (!uname) { - return NULL; - } GetTempPath(MAXPATHLEN, windir); l = strlen(windir); if ('\\' == windir[l-1]) { l--; } - snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%s@%.32s", ACCEL_FILEMAP_BASE, uname, accel_system_id); - free(uname); + snprintf(windir + l, sizeof(windir) - l - 1, "\\%s@%.32s@%.32s", ACCEL_FILEMAP_BASE, accel_uname_id, accel_system_id); return windir; } diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index 2a8bbcf6a0..64784f020b 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -325,6 +325,9 @@ ZEND_INI_BEGIN() STD_PHP_INI_BOOLEAN("opcache.huge_code_pages" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.huge_code_pages, zend_accel_globals, accel_globals) #endif STD_PHP_INI_ENTRY("opcache.preload" , "" , PHP_INI_SYSTEM, OnUpdateStringUnempty, accel_directives.preload, zend_accel_globals, accel_globals) +#if ZEND_WIN32 + STD_PHP_INI_ENTRY("opcache.cache_id" , "" , PHP_INI_SYSTEM, OnUpdateString, accel_directives.cache_id, zend_accel_globals, accel_globals) +#endif #ifdef HAVE_JIT STD_PHP_INI_ENTRY("opcache.jit" , ZEND_JIT_DEFAULT, PHP_INI_SYSTEM, OnUpdateLong, accel_directives.jit, zend_accel_globals, accel_globals) STD_PHP_INI_ENTRY("opcache.jit_buffer_size" , "0" , PHP_INI_SYSTEM, OnUpdateLong, accel_directives.jit_buffer_size, zend_accel_globals, accel_globals) @@ -789,6 +792,9 @@ static ZEND_FUNCTION(opcache_get_configuration) add_assoc_bool(&directives, "opcache.huge_code_pages", ZCG(accel_directives).huge_code_pages); #endif add_assoc_string(&directives, "opcache.preload", STRING_NOT_NULL(ZCG(accel_directives).preload)); +#if ZEND_WIN32 + add_assoc_string(&directives, "opcache.cache_id", STRING_NOT_NULL(ZCG(accel_directives).cache_id)); +#endif #ifdef HAVE_JIT add_assoc_long(&directives, "opcache.jit", ZCG(accel_directives).jit); add_assoc_long(&directives, "opcache.jit_buffer_size", ZCG(accel_directives).jit_buffer_size); diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index caff6ec1ce..1363e55468 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -835,31 +835,13 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path) memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path)); memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX)); #else - PHP_MD5_CTX ctx; - char md5uname[32]; - unsigned char digest[16], c; - size_t i; - char *uname = php_win32_get_username(); - - PHP_MD5Init(&ctx); - PHP_MD5Update(&ctx, uname, strlen(uname)); - PHP_MD5Final(digest, &ctx); - for (i = 0; i < 16; i++) { - c = digest[i] >> 4; - c = (c <= 9) ? c + '0' : c - 10 + 'a'; - md5uname[i * 2] = c; - c = digest[i] & 0x0f; - c = (c <= 9) ? c + '0' : c - 10 + 'a'; - md5uname[(i * 2) + 1] = c; - } - len = strlen(ZCG(accel_directives).file_cache); filename = emalloc(len + 33 + 33 + ZSTR_LEN(script_path) + sizeof(SUFFIX)); memcpy(filename, ZCG(accel_directives).file_cache, len); filename[len] = '\\'; - memcpy(filename + 1 + len, md5uname, 32); + memcpy(filename + 1 + len, accel_uname_id, 32); len += 1 + 32; filename[len] = '\\'; @@ -889,7 +871,6 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path) memcpy(filename + len + 33, ZSTR_VAL(script_path), ZSTR_LEN(script_path)); memcpy(filename + len + 33 + ZSTR_LEN(script_path), SUFFIX, sizeof(SUFFIX)); } - free(uname); #endif return filename; diff --git a/php.ini-development b/php.ini-development index 9f3b153a89..281dcdec6b 100644 --- a/php.ini-development +++ b/php.ini-development @@ -1823,6 +1823,10 @@ ldap.max_links = -1 ; errors. ;opcache.mmap_base= +; Facilitates multiple OPcache instances per user (for Windows only). All PHP +; processes with the same cache ID and user share an OPcache instance. +;opcache.cache_id= + ; Enables and sets the second level cache directory. ; It should improve performance when SHM memory is full, at server restart or ; SHM reset. The default "" disables file based caching. diff --git a/php.ini-production b/php.ini-production index 12807f8b6d..ae41df6b67 100644 --- a/php.ini-production +++ b/php.ini-production @@ -1825,6 +1825,10 @@ ldap.max_links = -1 ; errors. ;opcache.mmap_base= +; Facilitates multiple OPcache instances per user (for Windows only). All PHP +; processes with the same cache ID and user share an OPcache instance. +;opcache.cache_id= + ; Enables and sets the second level cache directory. ; It should improve performance when SHM memory is full, at server restart or ; SHM reset. The default "" disables file based caching. diff --git a/run-tests.php b/run-tests.php index f54dc2d37a..58e8fc1dba 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2076,7 +2076,7 @@ TEST $file } // Default ini settings - $ini_settings = array(); + $ini_settings = $workerID ? array('opcache.cache_id' => "worker$workerID") : array(); // Additional required extensions if (array_key_exists('EXTENSIONS', $section_text)) { |