Skip to content
Closed
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
26 changes: 18 additions & 8 deletions bin/createSwooleServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@

$sock = filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? SWOOLE_SOCK_TCP : SWOOLE_SOCK_TCP6;

$server = new Swoole\Http\Server(
$host,
$serverState['port'] ?? 8000,
$config['swoole']['mode'] ?? SWOOLE_PROCESS,
($config['swoole']['ssl'] ?? false)
? $sock | SWOOLE_SSL
: $sock,
);
$unixSock = $serverState['sock'] ?? null;
if (is_string($unixSock) && str_starts_with($unixSock, '/')) {
$server = new Swoole\Http\Server(
$unixSock, // Use UNIX socket
0, // Port is not needed
$config['swoole']['mode'] ?? SWOOLE_PROCESS,
SWOOLE_SOCK_UNIX_STREAM
);
} else {
$server = new Swoole\Http\Server(
$host,
$serverState['port'] ?? 8000,
$config['swoole']['mode'] ?? SWOOLE_PROCESS,
($config['swoole']['ssl'] ?? false)
? $sock | SWOOLE_SSL
: $sock,
);
}
} catch (Throwable $e) {
Laravel\Octane\Stream::shutdown($e);

Expand Down
8 changes: 7 additions & 1 deletion src/Commands/Concerns/InteractsWithServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ protected function writeServerRunningMessage()
{
$this->components->info('Server running…');

if ($this->option('sock')) {
$str = ' Local: <fg=white;options=bold>unix:'.$this->option('sock').' </>';
} else {
$str = ' Local: <fg=white;options=bold>'.($this->hasOption('https') && $this->option('https') ? 'https://' : 'http://').$this->getHost().':'.$this->getPort().' </>';
}

$this->output->writeln([
'',
' Local: <fg=white;options=bold>'.($this->hasOption('https') && $this->option('https') ? 'https://' : 'http://').$this->getHost().':'.$this->getPort().' </>',
$str,
'',
' <fg=yellow>Press Ctrl+C to stop the server</>',
'',
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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"]}
{--sock= : The unix domain socket the server should bind to [Swoole only]}
{--admin-port= : The port the admin server should be available on [FrankenPHP only]}
{--rpc-host= : The RPC IP address the server should bind to}
{--rpc-port= : The RPC port the server should be available on}
Expand Down Expand Up @@ -67,6 +68,7 @@ protected function startSwooleServer()
return $this->call('octane:swoole', [
'--host' => $this->getHost(),
'--port' => $this->getPort(),
'--sock' => $this->option('sock'),
'--workers' => $this->option('workers') ?: config('octane.workers', 'auto'),
'--task-workers' => $this->option('task-workers') ?: config('octane.task_workers', 'auto'),
'--max-requests' => $this->option('max-requests') ?: config('octane.max_requests', 500),
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/StartSwooleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class StartSwooleCommand extends Command implements SignalableCommandInterface
public $signature = 'octane:swoole
{--host= : The IP address the server should bind to}
{--port= : The port the server should be available on}
{--sock= : The unix socket the server should bind to [Swoole only]}
{--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,6 +106,7 @@ protected function writeServerStateFile(
'appName' => config('app.name', 'Laravel'),
'host' => $this->getHost(),
'port' => $this->getPort(),
'sock' => $this->option('sock'),
'workers' => $this->workerCount($extension),
'taskWorkers' => $this->taskWorkerCount($extension),
'maxRequests' => $this->option('max-requests'),
Expand Down