Skip to content

Commit e688569

Browse files
lonnieezellclaude
andcommitted
fix(#10615): probe underscore env names live under Apache mod_php
Under Apache mod_php, live getenv() reads SetEnv vars case-insensitively, so `SetEnv APP_BASEURL` matched `app_baseURL` in 4.8, but the indexed $_SERVER and getenv() array only hold the exact name. Probe the underscore forms live on any SAPI not known to match names exactly, keeping the cheaper path for CLI, FPM and FrankenPHP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ec9311b commit e688569

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎system/Config/BaseConfig.php‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
*/
3434
class BaseConfig
3535
{
36+
/**
37+
* SAPIs whose live getenv() only finds names, with the exact case, that are
38+
* also in $_SERVER or the getenv() array: the OS environment, plus FastCGI
39+
* params under FPM and FrankenPHP's own env layers.
40+
*/
41+
private const EXACT_ENV_SAPIS = ['cli', 'phpdbg', 'cli-server', 'fpm-fcgi', 'frankenphp'];
42+
3643
/**
3744
* An optional array of classes that will act as Registrars
3845
* for rapidly setting config class properties.
@@ -437,11 +444,15 @@ private static function findLiveEnvNames(array $values, string $prefix, string $
437444
self::$liveEnvNames[$prefix][$name] = [];
438445

439446
// Dot forms are never in the getenv() array, and underscore forms
440-
// only miss it when the name has " " or "[". On Windows, env var
441-
// names are case-insensitive, but only live getenv() calls match
442-
// them that way, so every form is probed there. Elsewhere that
443-
// would double the getenv() calls on a cold build for no gain.
444-
$envKeys = PHP_OS_FAMILY === 'Windows' || strpbrk($name, ' [') !== false
447+
// only miss it when the name has " " or "[". Live getenv() calls
448+
// also match names case-insensitively on Windows, and under
449+
// Apache mod_php, where they read SetEnv vars (e.g. APP_BASEURL
450+
// for app_baseURL). So every form is probed there, and under
451+
// any SAPI not known to match exactly. Elsewhere that would
452+
// double the getenv() calls on a cold build for no gain.
453+
$inexactEnv = PHP_OS_FAMILY === 'Windows' || ! in_array(PHP_SAPI, self::EXACT_ENV_SAPIS, true);
454+
455+
$envKeys = $inexactEnv || strpbrk($name, ' [') !== false
445456
? self::envKeys($name, $prefix, $shortPrefix)
446457
: ["{$shortPrefix}.{$name}", "{$prefix}.{$name}"];
447458

0 commit comments

Comments
 (0)