Skip to content

Commit 523f4c5

Browse files
authored
Use getenv() instead of $_ENV in bootstrap file to ensure environment variables are accessible
This PR updates the `bootstrap` file to use `getenv()` instead of `$_ENV` when retrieving environment variables. In some PHP configurations, `$_ENV` returns `null` unless the `variables_order` setting in `php.ini` includes the `E` flag. This can cause Octane to fail when resolving the application base path or vendor directory. By switching to `getenv()`, Octane can reliably fetch environment variables without requiring users to modify their PHP configuration. ### Changes - Replaced `$_ENV['APP_RUNNING_IN_CONSOLE']` with `getenv('APP_RUNNING_IN_CONSOLE')`. - Ensured `COMPOSER_VENDOR_DIR` and other variables are resolved consistently. ### Why When extending the Swoole server start process and attempting to change the vendor file path, `$_ENV` returned `null` unless `variables_order` was explicitly configured. This fix ensures smoother setup for developers across different environments. ### Impact - No breaking changes. - Improves reliability of environment variable handling in Swoole/Octane bootstrap.
1 parent 63d41c5 commit 523f4c5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

bin/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
|
1616
*/
1717

18-
$basePath = $_SERVER['APP_BASE_PATH'] ?? $_ENV['APP_BASE_PATH'] ?? $serverState['octaneConfig']['base_path'] ?? null;
18+
$basePath = $_SERVER['APP_BASE_PATH'] ?? getenv('APP_BASE_PATH') ?? $serverState['octaneConfig']['base_path'] ?? null;
1919

2020
if (! is_string($basePath)) {
2121
echo 'Cannot find application base path.';
@@ -35,7 +35,7 @@
3535
|
3636
*/
3737

38-
$vendorDir = $_ENV['COMPOSER_VENDOR_DIR'] ?? "{$basePath}/vendor";
38+
$vendorDir = getenv('COMPOSER_VENDOR_DIR') ?? "{$basePath}/vendor";
3939

4040
if (! is_file($autoload_file = "{$vendorDir}/autoload.php")) {
4141
echo "Composer autoload file was not found. Did you install the project's dependencies?";

0 commit comments

Comments
 (0)