[php-src] Issue #20470: Disable SHM reattachment

From: Date: Thu, 13 Nov 2025 13:26:33 +0000
Subject: [php-src] Issue #20470: Disable SHM reattachment
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251217@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20470 Author: arnaud-lb ### Description I'm opening this issue to restart the discussion started by @cmb69 in https://github.com/php/php-src/pull/17838 and https://github.com/php/php-src/pull/7865. Windows doesn't support fork(), so multi-process SAPIs spawn independent processes. Each process try to reattach the Opcache SHM of previous processes, which comes with a number of problems: 1. The SHM must be attached at the same address in all processes. If the address is not free in one process, reattachment can not happen. 2. When ASLR is enabled, some addresses referenced by SHM are invalid (such as opcode handler addresses stored in op arrays). Therefore, reattachment fails when ASLR is enabled ([source](https://github.com/php/php-src/blob/f1b73353e44afc84b5d48d082d29e43c9d1be2d3/ext/opcache/shared_alloc_win32.c#L138)). 3. The memory layout of each process can differ regardless of ASLR, for example when DLLs were loaded in a different order. Therefore, SHM can not usually reference addresses out of SHM. This leads to various Windows-specific workarounds and special cases in the code base. For example, the inheritance cache is disabled for sub-classes of internal classes. Additionally, this makes preloading incompatible with Windows, which blocks https://github.com/php/php-src/pull/18204. In cases 1 and 2, the process fails with a fatal error, or fallsback to file_cache_only mode (when enabled), which is slower. So processes can randomly fail or be slower. Case 2 implies that reattachment fails most of the times, now that ASLR is enabled by default. Because of these, I believe that it would be beneficial to disable reattachment entirely. Here is the impact on existing ways to deploy PHP, and required changes: #### IIS + FastCGI In this configuration IIS itself manages PHP processes. Unfortunately this enforces a process-based model, and reattachment is required so that concurrent requests share the same cache. I suggest that we deprecate this configuration in favor of other ones. #### Nginx + FastCGI In this configuration, php-cgi manages child processes itself. Therefore we can switch this SAPI to threads in ZTS builds so that reattachment is not necessary anymore. This would likely make the SAPI more resource-efficient on Windows as well. #### Apache + mod_php Uses [mpm_winnt](https://httpd.apache.org/docs/2.4/en/mod/mpm_winnt.html), which spawns a single process and multiple threads. Therefore, reattachment should not be necessary. See https://github.com/php/php-src/pull/7865. Additionally, @cmb69 started the implementation of an isapi-based SAPI: #### IIS + isapi Threaded, doesn't need reattachment See https://github.com/php/php-src/pull/17838.

« previous php.bugs (#251217) next »