|
33 | 33 | */ |
34 | 34 | class BaseConfig |
35 | 35 | { |
| 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 | + |
36 | 43 | /** |
37 | 44 | * An optional array of classes that will act as Registrars |
38 | 45 | * for rapidly setting config class properties. |
@@ -437,11 +444,15 @@ private static function findLiveEnvNames(array $values, string $prefix, string $ |
437 | 444 | self::$liveEnvNames[$prefix][$name] = []; |
438 | 445 |
|
439 | 446 | // 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 |
445 | 456 | ? self::envKeys($name, $prefix, $shortPrefix) |
446 | 457 | : ["{$shortPrefix}.{$name}", "{$prefix}.{$name}"]; |
447 | 458 |
|
|
0 commit comments