Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Read port for http server from environment if no port is passed #605

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Commands/Concerns/InteractsWithServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function writeServerRunningMessage()

$this->output->writeln([
'',
' Local: <fg=white;options=bold>http://'.$this->option('host').':'.$this->option('port').' </>',
' Local: <fg=white;options=bold>http://'.$this->option('host').':'.$this->getPort().' </>',
'',
' <fg=yellow>Press Ctrl+C to stop the server</>',
'',
Expand All @@ -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') ?? $_ENV['OCTANE_PORT'] ?? '8000';
}

/**
* Returns the list of signals to subscribe.
*
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hendrikheil This change is safe but slightly inconvenient as it removes the default port from the --help text of the command:

// Before
--port[=PORT]                  The port the server should be available on [default: "8000"]

// After
--port[=PORT]                  The port the server should be available on

Might be worth to add this to the text 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{--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}
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/StartRoadRunnerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/StartSwooleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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'),
Expand Down