Skip to content

Commit

Permalink
[2.x] Adds --admin-port (#790)
Browse files Browse the repository at this point in the history
* Adds `--admin-port`

* Update StartCommand.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
nunomaduro and taylorotwell authored Dec 21, 2023
1 parent de6e59b commit 6a625a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class StartCommand extends Command implements SignalableCommandInterface
{--server= : The server that should be used to serve the application}
{--host= : The IP address the server should bind to}
{--port= : The port the server should be available on [default: "8000"]}
{--admin-port= : The port the admin server should be available on [FrankenPHP only]}

This comment has been minimized.

Copy link
@francislavoie

francislavoie Dec 21, 2023

Contributor

Instead of this, I recommend making it --admin-address, because Caddy supports using a unix socket instead of a TCP socket. A unix socket would technically be a better default because it can be access controlled more easily with unix file permissions. But it's somewhat harder to use in a portable way, and it's a bit more awkward to use with HTTP clients if they aren't properly set up to connect to a unix socket.

{--rpc-host= : The RPC IP address the server should bind to}
{--rpc-port= : The RPC port the server should be available on}
{--workers=auto : The number of workers that should be available to handle requests}
Expand Down Expand Up @@ -102,6 +103,7 @@ protected function startFrankenPhpServer()
return $this->call('octane:frankenphp', [
'--host' => $this->getHost(),
'--port' => $this->getPort(),
'--admin-port' => $this->option('admin-port'),
'--workers' => $this->option('workers'),
'--max-requests' => $this->option('max-requests'),
'--caddyfile' => $this->option('caddyfile'),
Expand Down
13 changes: 12 additions & 1 deletion src/Commands/StartFrankenPhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class StartFrankenPhpCommand extends Command implements SignalableCommandInterfa
public $signature = 'octane:frankenphp
{--host=127.0.0.1 : The IP address the server should bind to}
{--port= : The port the server should be available on}
{--admin-port= : The port the admin 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}
{--caddyfile= : The path to the FrankenPHP Caddyfile file}
Expand Down Expand Up @@ -216,9 +217,19 @@ protected function writeServerStateFile(
*/
protected function adminPort()
{
if ($this->option('admin-port')) {
return (int) $this->option('admin-port');
}

$defaultPort = 2019;

return $defaultPort + ($this->getPort() - 8000);
return tap($defaultPort + ($this->getPort() - 8000), function ($adminPort) {
if ($adminPort < 0) {
throw new InvalidArgumentException(
'Unable to determine admin port. Please specify the [--admin-port] option.',
);
}
});
}

/**
Expand Down

0 comments on commit 6a625a8

Please sign in to comment.