[php-src] PHP-8.4: fix: system ID for Apache graceful restart (#24184)
| From: | Levi Morrison via GitHub | Date: | Fri, 09 Oct 2026 15:10:52 +0000 |
| Subject: | [php-src] PHP-8.4: fix: system ID for Apache graceful restart (#24184) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142118@lists.php.net to get a copy of this message | ||
Author: Levi Morrison (morrisonlevi)
Committer: GitHub (web-flow)
Pusher: morrisonlevi
Date: 2026-10-09T09:10:48-06:00
Commit: https://github.com/php/php-src/commit/695f8264f746602b43d93a3998be9d91c4b3655d
Raw diff: https://github.com/php/php-src/commit/695f8264f746602b43d93a3998be9d91c4b3655d.diff
fix: system ID for Apache graceful restart (#24184)
Apache forks workers from a parent process. During a graceful
restart, PHP shuts down and starts up again in that same parent
process.
However,
finalized was not reset to 0 during subsequent startups,
so all calls to zend_add_system_entropy() would fail. This could
cause the process state to diverge from the system ID used to
validate OPcache's file cache.
For example, zend_get_resource_handle() would still allocate a
handle, but its entropy would not contribute to the system ID.
Enabling, disabling, or reordering extensions or features across
graceful restarts could therefore change resource-slot assignments
without a corresponding change to the system ID.
Reset finalized when initializing the system ID so each startup
can register fresh entropy.
Changed paths:
A ext/zend_test/tests/system_id_reinitialization.phpt
M NEWS
M Zend/zend_system_id.c
M ext/zend_test/test.c
Diff:
diff --git a/NEWS b/NEWS
index 64d75dfc03ad..8dc808543b73 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ PHP NEWS
?? ??? ????, PHP 8.4.28
- Core:
+ . Fixed bug GH-24184 (System ID not being reinitialized after an Apache
+ graceful restart, potentially causing incompatible OPcache file cache
+ entries to be reused). (Levi Morrison)
. Fixed memory leak when an exception already contains the pending exception
in its previous chain. (Edmond)
. Fixed bug GH-23979 (Nullsafe operator must not flush delayed oplines of an
diff --git a/Zend/zend_system_id.c b/Zend/zend_system_id.c
index 2c3ebab0f480..34142d959710 100644
--- a/Zend/zend_system_id.c
+++ b/Zend/zend_system_id.c
@@ -43,6 +43,7 @@ ZEND_API zend_result zend_add_system_entropy(const char *module_name, const char
void zend_startup_system_id(void)
{
+ finalized = 0;
PHP_MD5Init(&context);
PHP_MD5Update(&context, PHP_VERSION, sizeof(PHP_VERSION)-1);
PHP_MD5Update(&context, ZEND_EXTENSION_BUILD_ID, sizeof(ZEND_EXTENSION_BUILD_ID)-1);
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index c5ae9a71c203..718def0b31c5 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -36,6 +36,7 @@
#include "test_arginfo.h"
#include "zend_call_stack.h"
#include "zend_exceptions.h"
+#include "zend_system_id.h"
#include "zend_mm_custom_handlers.h"
#include <signal.h>
@@ -1180,6 +1181,7 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call)
}
PHP_INI_BEGIN()
+ PHP_INI_ENTRY("zend_test.register_system_entropy", "0", PHP_INI_SYSTEM, NULL)
STD_PHP_INI_BOOLEAN("zend_test.replace_zend_execute_ex", "0", PHP_INI_SYSTEM,
OnUpdateBool, replace_zend_execute_ex, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.register_passes", "0", PHP_INI_SYSTEM,
OnUpdateBool, register_passes, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.print_stderr_mshutdown", "0", PHP_INI_SYSTEM,
OnUpdateBool, print_stderr_mshutdown, zend_zend_test_globals, zend_test_globals)
@@ -1378,6 +1380,10 @@ PHP_MINIT_FUNCTION(zend_test)
// Loading via dl() not supported with the observer API
if (type != MODULE_TEMPORARY) {
REGISTER_INI_ENTRIES();
+ if (INI_BOOL("zend_test.register_system_entropy") &&
+ zend_add_system_entropy("zend_test", "test", ZEND_STRL("test
entropy")) == FAILURE) {
+ php_error_docref(NULL, E_WARNING, "Failed to register system entropy");
+ }
} else {
(void)ini_entries;
}
diff --git a/ext/zend_test/tests/system_id_reinitialization.phpt
b/ext/zend_test/tests/system_id_reinitialization.phpt
new file mode 100644
index 000000000000..5e80b567c621
--- /dev/null
+++ b/ext/zend_test/tests/system_id_reinitialization.phpt
@@ -0,0 +1,40 @@
+--TEST--
+System ID reinitialization accepts extension entropy after engine restart
+--SKIPIF--
+<?php
+if (!extension_loaded('zend_test')) die('skip zend_test extension required');
+?>
+--INI--
+zend_test.register_system_entropy=1
+--PHPDBG--
+r
+clean
+r
+clean
+r
+q
+--FILE--
+<?php
+echo "Done\n";
+?>
+--EXPECTF--
+[Successful compilation of %s]
+prompt> Done
+[Script ended normally]
+prompt> Cleaning Execution Environment
+Classes %d
+Functions %d
+Constants %d
+Includes 0
+[Script ended normally]
+prompt> Done
+[Script ended normally]
+prompt> Cleaning Execution Environment
+Classes %d
+Functions %d
+Constants %d
+Includes 0
+[Script ended normally]
+prompt> Done
+[Script ended normally]
+prompt>