fix(worker): initialize $_RESUEST (#2136)

Hi,

This PR fixes #1931, it handles $_REQUEST in worker mode correctly when
`auto_globals_jit` is enabled (default configuration for PHP).
Some concerns were raised in the comments of the issue regarding
performance. This implementation should make sure that request is
created only if used.

However if a previous execution plan already used `_REQUEST`, all
subsequent requests will create it. So the concern is "kindof"
mitigated.

Let me know if you have any suggestion to improve this.

---------

Signed-off-by: Xavier Leune <xavier.leune@gmail.com>
Co-authored-by: Alexander Stecher <45872305+AlliBalliBaba@users.noreply.github.com>
This commit is contained in:
Xavier Leune
2026-01-29 06:56:45 +01:00
committed by GitHub
parent ddb11c1f72
commit 0e8de8f56f
5 changed files with 111 additions and 5 deletions

View File

@@ -0,0 +1,20 @@
<?php
// This file tests if $_REQUEST is properly re-initialized in worker mode
// The key test is: does $_REQUEST contain ONLY the current request's data?
// Static counter to track how many times this file is executed (not compiled)
static $execCount = 0;
$execCount++;
echo "EXEC_COUNT:" . $execCount;
echo "\nREQUEST:";
var_export($_REQUEST);
echo "\nREQUEST_COUNT:" . count($_REQUEST);
// Check if $_REQUEST was properly initialized for this request
// If stale, it might have data from a previous request
if (isset($_GET['val'])) {
$expected_val = $_GET['val'];
$actual_val = $_REQUEST['val'] ?? 'MISSING';
echo "\nVAL_CHECK:" . ($expected_val === $actual_val ? "MATCH" : "MISMATCH(expected=$expected_val,actual=$actual_val)");
}

View File

@@ -0,0 +1,16 @@
<?php
require_once __DIR__.'/_executor.php';
return function () {
// Only access $_REQUEST on requests where use_request=1 is passed
// This tests the "re-arm" scenario where $_REQUEST might be accessed
// for the first time during a later request
if (isset($_GET['use_request']) && $_GET['use_request'] === '1') {
include 'request-superglobal-conditional-include.php';
} else {
echo "SKIPPED";
}
echo "\nGET:";
var_export($_GET);
};

14
testdata/request-superglobal.php vendored Normal file
View File

@@ -0,0 +1,14 @@
<?php
require_once __DIR__.'/_executor.php';
return function () {
// Output $_REQUEST to verify it contains current request data
// $_REQUEST should be a merge of $_GET and $_POST (based on request_order)
echo "REQUEST:";
var_export($_REQUEST);
echo "\nGET:";
var_export($_GET);
echo "\nPOST:";
var_export($_POST);
};