1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/opcache/tests/gh18417.phpt
Niels Dossche 7869af6fa8 Fix GH-18417: Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size
When a first PHP process launches, Opcache creates a shared file mapping
to use as a shm region. The size of this mapping is set by
opcache.memory_consumption.
When a new PHP process launches while the old one is still running,
Opcache tries to reattach to the shm.
When reattaching it tries to map the requested size (i.e. set by
opcache.memory_consumption). However, if the new requested size is
larger than the size used in the original file mapping, then the call
to VirtualProtect() will fail and the new PHP process will fail to
launch.
It's not possible to resize the virtual region on Windows, unless
relying on undocumented APIs like `NtExtendSection` but then we would
sitll need to communicate that to the first process.

This issue is the root cause of Psalm end-to-end tests failing in
GH-18417: Psalm estimates the required memory sizes and relaunches itself
with more memory requested, if its estimate is below the currently allocated
shared memory. This causes a crash on startup and the tests fail.

To solve this, we need to make the mappings unique per requested size.
There are two ideas:
1. Include in zend_system_id. However, this also affects other things
   and may be too overkill.
2. Include it in the filename, this is an easy local change.
   I went with this option.

Closes GH-18443.
2025-04-28 19:51:31 +02:00

41 lines
973 B
PHP

--TEST--
GH-18417 (Windows SHM reattachment fails when increasing memory_consumption or jit_buffer_size)
--SKIPIF--
<?php
$extDir = ini_get('extension_dir');
if (!file_exists($extDir . '/php_opcache.dll')) {
die('skip Opcache DLL not found in extension_dir (Windows-only)');
}
?>
--FILE--
<?php
$memory_consumption = (int) ini_get("opcache.memory_consumption");
$new_memory_consumption = $memory_consumption * 2;
$extension_dir = ini_get("extension_dir");
$descriptorspec = [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"],
];
$proc = proc_open([
PHP_BINARY,
"-n",
"-d", "extension_dir=$extension_dir",
"-d", "zend_extension=opcache",
"-d", "opcache.memory_consumption=$new_memory_consumption",
"-d", "opcache.enable=1",
"-d", "opcache.enable_cli=1",
"-r",
"echo 1;"
], $descriptorspec, $pipes);
echo stream_get_contents($pipes[1]);
echo stream_get_contents($pipes[2]);
proc_close($proc);
?>
--EXPECT--
1