1 | <?php |
||
10 | class LaravooleCommand extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'laravoole {action : start | stop | reload | reload_task | restart | quit}'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Start laravoole'; |
||
25 | |||
26 | /** |
||
27 | * Create a new command instance. |
||
28 | * |
||
29 | * @return void |
||
|
|||
30 | */ |
||
31 | public function __construct() |
||
35 | |||
36 | /** |
||
37 | * Execute the console command. |
||
38 | * |
||
39 | * @return mixed |
||
40 | */ |
||
41 | public function handle() |
||
42 | { |
||
43 | switch ($action = $this->argument('action')) { |
||
44 | |||
45 | case 'start': |
||
46 | $this->start(); |
||
47 | break; |
||
48 | case 'restart': |
||
49 | $pid = $this->sendSignal(SIGTERM); |
||
50 | $time = 0; |
||
51 | while (posix_getpgid($pid) && $time <= 10) { |
||
52 | usleep(100000); |
||
53 | $time++; |
||
54 | } |
||
55 | if ($time > 100) { |
||
56 | echo 'timeout' . PHP_EOL; |
||
57 | exit(1); |
||
58 | } |
||
59 | $this->start(); |
||
60 | break; |
||
61 | case 'stop': |
||
62 | case 'quit': |
||
63 | case 'reload': |
||
64 | case 'reload_task': |
||
65 | |||
66 | $map = [ |
||
67 | 'stop' => SIGTERM, |
||
68 | 'quit' => SIGQUIT, |
||
69 | 'reload' => SIGUSR1, |
||
70 | 'reload_task' => SIGUSR2, |
||
71 | ]; |
||
72 | $this->sendSignal($map[$action]); |
||
73 | break; |
||
74 | |||
75 | } |
||
76 | } |
||
77 | |||
78 | protected function sendSignal($sig) |
||
89 | |||
90 | protected function start() |
||
161 | |||
162 | protected function getPid() |
||
176 | |||
177 | } |
||
178 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.