diff --git a/CHANGELOG.md b/CHANGELOG.md index 066b01f9f..aa085d6f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased](https://github.com/laravel/octane/compare/v0.4.0...master) +> **Requires to stop, and re-start your Octane server** + +### Fixed +- Global environment variables not being taken in by workers ([#257](https://github.com/laravel/octane/pull/257)) ## [v0.4.0 (2021-04-27)](https://github.com/laravel/octane/compare/v0.3.2...v0.4.0) diff --git a/src/Commands/Concerns/InteractsWithEnvironmentVariables.php b/src/Commands/Concerns/InteractsWithEnvironmentVariables.php new file mode 100644 index 000000000..e20681289 --- /dev/null +++ b/src/Commands/Concerns/InteractsWithEnvironmentVariables.php @@ -0,0 +1,37 @@ +addPath(app()->environmentPath()) + ->addName(app()->environmentFile()) + ->make() + ->read(); + + foreach ((new Parser())->parse($content) as $entry) { + $variables->push($entry->getName()); + } + } catch (InvalidPathException $e) { + // .. + } + + $variables->each(fn ($name) => Env::getRepository()->clear($name)); + } +} diff --git a/src/Commands/StartRoadRunnerCommand.php b/src/Commands/StartRoadRunnerCommand.php index 653259916..4776c6029 100644 --- a/src/Commands/StartRoadRunnerCommand.php +++ b/src/Commands/StartRoadRunnerCommand.php @@ -11,7 +11,9 @@ class StartRoadRunnerCommand extends Command implements SignalableCommandInterface { - use Concerns\InstallsRoadRunnerDependencies, Concerns\InteractsWithServers; + use Concerns\InstallsRoadRunnerDependencies, + Concerns\InteractsWithServers, + Concerns\InteractsWithEnvironmentVariables; /** * The command's signature. @@ -69,6 +71,8 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve touch(base_path('.rr.yaml')); + $this->forgetEnvironmentVariables(); + $server = tap(new Process(array_filter([ $roadRunnerBinary, '-c', base_path('.rr.yaml'), @@ -85,13 +89,11 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve '-o', 'logs.output=stdout', '-o', 'logs.encoding=json', '--dotenv=""', 'serve', - ]), base_path(), collect(array_merge($_ENV, [ + ]), base_path(), [ + 'APP_ENV' => app()->environment(), 'APP_BASE_PATH' => base_path(), - 'LARAVEL_OCTANE' => 1, ]))->mapWithKeys(function ($value, $key) { - return in_array($key, ['APP_ENV', 'APP_BASE_PATH', 'LARAVEL_OCTANE']) - ? [$key => $value] - : [$key => false]; - })->all(), null, null))->start(); + 'LARAVEL_OCTANE' => 1, + ]))->start(); $serverStateFile->writeProcessId($server->getPid()); diff --git a/src/Commands/StartSwooleCommand.php b/src/Commands/StartSwooleCommand.php index 1814ab40e..2ae94cef3 100644 --- a/src/Commands/StartSwooleCommand.php +++ b/src/Commands/StartSwooleCommand.php @@ -12,7 +12,7 @@ class StartSwooleCommand extends Command implements SignalableCommandInterface { - use Concerns\InteractsWithServers; + use Concerns\InteractsWithServers, Concerns\InteractsWithEnvironmentVariables; /** * The command's signature. @@ -68,15 +68,15 @@ public function handle( $this->writeServerStateFile($serverStateFile, $extension); + $this->forgetEnvironmentVariables(); + $server = tap(new Process([ (new PhpExecutableFinder)->find(), 'swoole-server', $serverStateFile->path(), - ], realpath(__DIR__.'/../../bin'), collect(array_merge($_ENV, [ + ], realpath(__DIR__.'/../../bin'), [ + 'APP_ENV' => app()->environment(), 'APP_BASE_PATH' => base_path(), - 'LARAVEL_OCTANE' => 1, ]))->mapWithKeys(function ($value, $key) { - return in_array($key, ['APP_ENV', 'APP_BASE_PATH', 'LARAVEL_OCTANE']) - ? [$key => $value] - : [$key => false]; - })->all(), null, null))->start(); + 'LARAVEL_OCTANE' => 1, + ]))->start(); return $this->runServer($server, $inspector, 'swoole'); }