From 88f589fa235951b01c0603eb79dc7e06bb15e592 Mon Sep 17 00:00:00 2001 From: Hendrik Heil Date: Mon, 31 Oct 2022 10:11:19 +0100 Subject: [PATCH 1/4] feat: add support for environment defined port --- src/Commands/Concerns/InteractsWithServers.php | 12 +++++++++++- src/Commands/StartCommand.php | 6 +++--- src/Commands/StartRoadRunnerCommand.php | 8 ++++---- src/Commands/StartSwooleCommand.php | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index 1392d9c04..583d01459 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -100,7 +100,7 @@ protected function writeServerRunningMessage() $this->output->writeln([ '', - ' Local: http://'.$this->option('host').':'.$this->option('port').' ', + ' Local: http://'.$this->option('host').':'.$this->getPort().' ', '', ' Press Ctrl+C to stop the server', '', @@ -140,4 +140,14 @@ public function handleSignal(int $signal): void { $this->stopServer(); } + + /** + * Get the HTTP server port + * + * @return int + */ + protected function getPort() + { + return $this->option('port') ?? env('SERVER_PORT') ?? '8000'; + } } diff --git a/src/Commands/StartCommand.php b/src/Commands/StartCommand.php index 7842f10e4..72176b1e0 100644 --- a/src/Commands/StartCommand.php +++ b/src/Commands/StartCommand.php @@ -16,7 +16,7 @@ class StartCommand extends Command implements SignalableCommandInterface public $signature = 'octane:start {--server= : The server that should be used to serve the application} {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on} {--rpc-port= : The RPC port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--task-workers=auto : The number of task workers that should be available to handle tasks} @@ -57,7 +57,7 @@ protected function startSwooleServer() { return $this->call('octane:swoole', [ '--host' => $this->option('host'), - '--port' => $this->option('port'), + '--port' => $this->getPort(), '--workers' => $this->option('workers'), '--task-workers' => $this->option('task-workers'), '--max-requests' => $this->option('max-requests'), @@ -75,7 +75,7 @@ protected function startRoadRunnerServer() { return $this->call('octane:roadrunner', [ '--host' => $this->option('host'), - '--port' => $this->option('port'), + '--port' => $this->getPort(), '--rpc-port' => $this->option('rpc-port'), '--workers' => $this->option('workers'), '--max-requests' => $this->option('max-requests'), diff --git a/src/Commands/StartRoadRunnerCommand.php b/src/Commands/StartRoadRunnerCommand.php index 1fbea0a39..a201e4b00 100644 --- a/src/Commands/StartRoadRunnerCommand.php +++ b/src/Commands/StartRoadRunnerCommand.php @@ -23,7 +23,7 @@ class StartRoadRunnerCommand extends Command implements SignalableCommandInterfa */ public $signature = 'octane:roadrunner {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on} {--rpc-port= : The RPC port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--max-requests=500 : The number of requests to process before reloading the server} @@ -79,7 +79,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve $roadRunnerBinary, '-c', $this->configPath(), '-o', 'version=2.7', - '-o', 'http.address='.$this->option('host').':'.$this->option('port'), + '-o', 'http.address='.$this->option('host').':'.$this->getPort(), '-o', 'server.command='.(new PhpExecutableFinder)->find().' '.base_path(config('octane.roadrunner.command', 'vendor/bin/roadrunner-worker')), '-o', 'http.pool.num_workers='.$this->workerCount(), '-o', 'http.pool.max_jobs='.$this->option('max-requests'), @@ -115,7 +115,7 @@ protected function writeServerStateFile( $serverStateFile->writeState([ 'appName' => config('app.name', 'Laravel'), 'host' => $this->option('host'), - 'port' => $this->option('port'), + 'port' => $this->getPort(), 'rpcPort' => $this->rpcPort(), 'workers' => $this->workerCount(), 'maxRequests' => $this->option('max-requests'), @@ -174,7 +174,7 @@ protected function maxExecutionTime() */ protected function rpcPort() { - return $this->option('rpc-port') ?: $this->option('port') - 1999; + return $this->option('rpc-port') ?: $this->getPort() - 1999; } /** diff --git a/src/Commands/StartSwooleCommand.php b/src/Commands/StartSwooleCommand.php index 4a8ac740b..51da273e9 100644 --- a/src/Commands/StartSwooleCommand.php +++ b/src/Commands/StartSwooleCommand.php @@ -21,7 +21,7 @@ class StartSwooleCommand extends Command implements SignalableCommandInterface */ public $signature = 'octane:swoole {--host=127.0.0.1 : The IP address the server should bind to} - {--port=8000 : The port the server should be available on} + {--port= : The port the server should be available on} {--workers=auto : The number of workers that should be available to handle requests} {--task-workers=auto : The number of task workers that should be available to handle tasks} {--max-requests=500 : The number of requests to process before reloading the server} @@ -105,7 +105,7 @@ protected function writeServerStateFile( $serverStateFile->writeState([ 'appName' => config('app.name', 'Laravel'), 'host' => $this->option('host'), - 'port' => $this->option('port'), + 'port' => $this->getPort(), 'workers' => $this->workerCount($extension), 'taskWorkers' => $this->taskWorkerCount($extension), 'maxRequests' => $this->option('max-requests'), From 8ea4d9911fd51789e3760432b613e0b9d23107c9 Mon Sep 17 00:00:00 2001 From: Hendrik Heil Date: Mon, 31 Oct 2022 10:55:29 +0100 Subject: [PATCH 2/4] chore: fix styleci errors --- src/Commands/Concerns/InteractsWithServers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index 583d01459..004c909a1 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -142,7 +142,7 @@ public function handleSignal(int $signal): void } /** - * Get the HTTP server port + * Get the HTTP server port. * * @return int */ From 92ff8298fd698966d8d92b6b498fcff52e1e0916 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 31 Oct 2022 13:58:00 -0500 Subject: [PATCH 3/4] formatting --- .../Concerns/InteractsWithServers.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index 004c909a1..bde1903a8 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -120,6 +120,16 @@ protected function getServerOutput($server) ], fn () => $server->clearOutput()->clearErrorOutput()); } + /** + * Get the Octane HTTP server port. + * + * @return string + */ + protected function getPort() + { + return $this->option('port') ?? config('octane.port') ?? '8000'; + } + /** * Returns the list of signals to subscribe. * @@ -140,14 +150,4 @@ public function handleSignal(int $signal): void { $this->stopServer(); } - - /** - * Get the HTTP server port. - * - * @return int - */ - protected function getPort() - { - return $this->option('port') ?? env('SERVER_PORT') ?? '8000'; - } } From 6b36c78b3d157e8304b8ad110af4961123755441 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 31 Oct 2022 13:58:50 -0500 Subject: [PATCH 4/4] use env --- src/Commands/Concerns/InteractsWithServers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Concerns/InteractsWithServers.php b/src/Commands/Concerns/InteractsWithServers.php index bde1903a8..f97eb684e 100644 --- a/src/Commands/Concerns/InteractsWithServers.php +++ b/src/Commands/Concerns/InteractsWithServers.php @@ -127,7 +127,7 @@ protected function getServerOutput($server) */ protected function getPort() { - return $this->option('port') ?? config('octane.port') ?? '8000'; + return $this->option('port') ?? config('octane.port') ?? $_ENV['OCTANE_PORT'] ?? '8000'; } /**