From aaa7c8876044c1b5291a2e321786f3409ecb97ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Jul 2025 10:27:53 +0200 Subject: [PATCH 1/2] opcache: Reset `accel_startup_ok` after shutting down This is necessary for phpdbg, which runs multiple startup/shutdown cycles in the same process. --- ext/opcache/ZendAccelerator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 0f1f1c986985b..dd063c67e1546 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3509,6 +3509,8 @@ void accel_shutdown(void) if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives), "include_path", sizeof("include_path")-1)) != NULL) { ini_entry->on_modify = orig_include_path_on_modify; } + + accel_startup_ok = false; } void zend_accel_schedule_restart(zend_accel_restart_reason reason) From 3265c7c68311007d9e77d2052ddd0d6b6006cfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 16 Jul 2025 09:55:12 +0200 Subject: [PATCH 2/2] opcache: Disallow changing `opcache.memory_consumption` when SHM is set up Normally changing the INI value is not possible after SHM is set up, since it is `PHP_INI_SYSTEM`. FPM is a notable exception: SHM is set up in the master process, but when spawning the individual pools, the `php_admin_value` config option can be used to change `PHP_INI_SYSTEM` INIs on a per-pool basis. This does not work for this option, since it will only be read on early start, leading to misleading PHPInfo output, since the INI value appears to be successfully set and since some of the calculated values are derived from the INI value rather than the actual value. --- NEWS | 4 ++++ UPGRADING | 3 +++ ext/opcache/zend_accelerator_module.c | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/NEWS b/NEWS index 6929e7b2d2f14..0f4213fc87716 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.5.0alpha3 +- OPcache: + . Disallow changing opcache.memory_consumption when SHM is already set up. + (timwolla) + - Sockets: . socket_set_option for multicast context throws a ValueError when the socket family is not of AF_INET/AF_INET6 family. (David Carlier) diff --git a/UPGRADING b/UPGRADING index 2a82975517178..2549fe74cbfe0 100644 --- a/UPGRADING +++ b/UPGRADING @@ -571,6 +571,9 @@ PHP 8.5 UPGRADE NOTES . The default value of opcache.jit_hot_loop is now 61 (a prime) to prevent it from being a multiple of loop iteration counts. It is recommended that this parameter is set to a prime number. + . Changing opcache.memory_consumption when OPcache SHM is already set up + will now correctly report a failure instead of silently doing nothing and + showing misleading values in PHPInfo. - OpenSSL: Added openssl.libctx to select the OpenSSL library context type. Either diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index a4f632872f546..9d5881f3e56f2 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -76,6 +76,15 @@ static int validate_api_restriction(void) static ZEND_INI_MH(OnUpdateMemoryConsumption) { + if (accel_startup_ok) { + if (strcmp(sapi_module.name, "fpm-fcgi") == 0) { + zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption cannot be changed when OPcache is already set up. Are you using php_admin_value[opcache.memory_consumption] in an individual pool's configuration?\n"); + } else { + zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption cannot be changed when OPcache is already set up.\n"); + } + return FAILURE; + } + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); zend_long memsize = atoi(ZSTR_VAL(new_value)); /* sanity check we must use at least 8 MB */