-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathStartCommand.php
117 lines (104 loc) · 3.7 KB
/
StartCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Laravel\Octane\Commands;
use Symfony\Component\Console\Command\SignalableCommandInterface;
class StartCommand extends Command implements SignalableCommandInterface
{
use Concerns\InteractsWithServers;
/**
* The command's signature.
*
* @var string
*/
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= : The port the server should be available on [default: "8000"]}
{--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}
{--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}
{--rr-config= : The path to the RoadRunner .rr.yaml file}
{--watch : Automatically reload the server when the application is modified}
{--poll : Use file system polling while watching in order to watch files over a network}
{--log-level= : Log messages at or above the specified log level}';
/**
* The command's description.
*
* @var string
*/
public $description = 'Start the Octane server';
/**
* Handle the command.
*
* @return int
*/
public function handle()
{
$server = $this->option('server') ?: config('octane.server');
return match ($server) {
'swoole' => $this->startSwooleServer(),
'roadrunner' => $this->startRoadRunnerServer(),
default => $this->invalidServer($server),
};
}
/**
* Start the Swoole server for Octane.
*
* @return int
*/
protected function startSwooleServer()
{
return $this->call('octane:swoole', [
'--host' => $this->getHost(),
'--port' => $this->getPort(),
'--workers' => $this->option('workers'),
'--task-workers' => $this->option('task-workers'),
'--max-requests' => $this->option('max-requests'),
'--watch' => $this->option('watch'),
'--poll' => $this->option('poll'),
]);
}
/**
* Start the RoadRunner server for Octane.
*
* @return int
*/
protected function startRoadRunnerServer()
{
return $this->call('octane:roadrunner', [
'--host' => $this->getHost(),
'--port' => $this->getPort(),
'--rpc-host' => $this->option('rpc-host'),
'--rpc-port' => $this->option('rpc-port'),
'--workers' => $this->option('workers'),
'--max-requests' => $this->option('max-requests'),
'--rr-config' => $this->option('rr-config'),
'--watch' => $this->option('watch'),
'--poll' => $this->option('poll'),
'--log-level' => $this->option('log-level'),
]);
}
/**
* Inform the user that the server type is invalid.
*
* @return int
*/
protected function invalidServer(string $server)
{
$this->error("Invalid server: {$server}.");
return 1;
}
/**
* Stop the server.
*
* @return void
*/
protected function stopServer()
{
$server = $this->option('server') ?: config('octane.server');
$this->callSilent('octane:stop', [
'--server' => $server,
]);
}
}