@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $server[$headerServerMapping[$key]] = $value; |
52 | 52 | } else { |
53 | 53 | $key = str_replace('-', '_', $key); |
54 | - $server['http_' . $key] = $value; |
|
54 | + $server['http_'.$key] = $value; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | $server = array_change_key_case($server, CASE_UPPER); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | && isset($_SERVER['QUERY_STRING']) |
66 | 66 | && $_SERVER['QUERY_STRING'] !== '' |
67 | 67 | ) { |
68 | - $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
68 | + $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Fix argv & argc |
@@ -19,17 +19,17 @@ |
||
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | - $fileTypes = isset($config['file_types']) ? (array)$config['file_types'] : []; |
|
22 | + $fileTypes = isset($config['file_types']) ? (array) $config['file_types'] : []; |
|
23 | 23 | if (empty($fileTypes)) { |
24 | 24 | $this->warning('No file types to watch by inotify'); |
25 | 25 | return false; |
26 | 26 | } |
27 | 27 | |
28 | - $callback = function () use ($config, $laravelConf) { |
|
28 | + $callback = function() use ($config, $laravelConf) { |
|
29 | 29 | $log = !empty($config['log']); |
30 | 30 | $this->setProcessTitle(sprintf('%s laravels: inotify process', $config['process_prefix'])); |
31 | 31 | $inotify = new Inotify($config['watch_path'], IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVE, |
32 | - function ($event) use ($log, $laravelConf) { |
|
32 | + function($event) use ($log, $laravelConf) { |
|
33 | 33 | Portal::runLaravelSCommand($laravelConf['root_path'], 'reload'); |
34 | 34 | if ($log) { |
35 | 35 | $action = 'file:'; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | public function addCustomProcesses(Server $swoole, $processPrefix, array $processes, array $laravelConfig) |
13 | 13 | { |
14 | - $pidfile = dirname($swoole->setting['pid_file']) . '/' . $this->customProcessPidFile; |
|
14 | + $pidfile = dirname($swoole->setting['pid_file']).'/'.$this->customProcessPidFile; |
|
15 | 15 | if (file_exists($pidfile)) { |
16 | 16 | unlink($pidfile); |
17 | 17 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | continue; |
27 | 27 | } |
28 | 28 | $processClass = $item['class']; |
29 | - $restartInterval = isset($item['restart_interval']) ? (int)$item['restart_interval'] : 5; |
|
30 | - $callback = function (Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) { |
|
31 | - file_put_contents($pidfile, $worker->pid . "\n", FILE_APPEND | LOCK_EX); |
|
29 | + $restartInterval = isset($item['restart_interval']) ? (int) $item['restart_interval'] : 5; |
|
30 | + $callback = function(Process $worker) use ($pidfile, $swoole, $processPrefix, $processClass, $restartInterval, $name, $laravelConfig) { |
|
31 | + file_put_contents($pidfile, $worker->pid."\n", FILE_APPEND | LOCK_EX); |
|
32 | 32 | $this->initLaravel($laravelConfig, $swoole); |
33 | 33 | if (!isset(class_implements($processClass)[CustomProcessInterface::class])) { |
34 | 34 | throw new \InvalidArgumentException( |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | /**@var CustomProcessInterface $processClass */ |
43 | 43 | $this->setProcessTitle(sprintf('%s laravels: %s process', $processPrefix, $name)); |
44 | 44 | |
45 | - Process::signal(SIGUSR1, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
45 | + Process::signal(SIGUSR1, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
46 | 46 | $this->info(sprintf('Reloading %s process[PID=%d].', $name, $worker->pid)); |
47 | 47 | $processClass::onReload($swoole, $worker); |
48 | 48 | }); |
49 | 49 | |
50 | 50 | if (method_exists($processClass, 'onStop')) { |
51 | - Process::signal(SIGTERM, function ($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
51 | + Process::signal(SIGTERM, function($signo) use ($name, $processClass, $worker, $pidfile, $swoole) { |
|
52 | 52 | $this->info(sprintf('Stopping %s process[PID=%d].', $name, $worker->pid)); |
53 | 53 | $processClass::onStop($swoole, $worker); |
54 | 54 | }); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | for ($i = 0; $i < $item['num']; $i++) { |
73 | 73 | $process = $this->makeProcess($callback, $item); |
74 | 74 | $swoole->addProcess($process); |
75 | - $processList[$name . $i] = $process; |
|
75 | + $processList[$name.$i] = $process; |
|
76 | 76 | } |
77 | 77 | } else { // For single process |
78 | 78 | $process = $this->makeProcess($callback, $item); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | 'value' => $apcSmaInfo['avail_mem'], |
31 | 31 | ], |
32 | 32 | ]; |
33 | - foreach (new \APCuIterator('/^' . $this->config['apcu_key_prefix'] . $this->config['apcu_key_separator'] . '/') as $item) { |
|
33 | + foreach (new \APCuIterator('/^'.$this->config['apcu_key_prefix'].$this->config['apcu_key_separator'].'/') as $item) { |
|
34 | 34 | $parts = explode($this->config['apcu_key_separator'], $item['key']); |
35 | 35 | parse_str($parts[3], $labels); |
36 | 36 | if (is_array($item['value'])) { |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | $metrics = $this->getMetrics(); |
63 | 63 | $lines = []; |
64 | 64 | foreach ($metrics as $metric) { |
65 | - $lines[] = "# HELP " . $metric['name'] . " {$metric['help']}"; |
|
66 | - $lines[] = "# TYPE " . $metric['name'] . " {$metric['type']}"; |
|
65 | + $lines[] = "# HELP ".$metric['name']." {$metric['help']}"; |
|
66 | + $lines[] = "# TYPE ".$metric['name']." {$metric['type']}"; |
|
67 | 67 | |
68 | 68 | $metricLabels = isset($metric['labels']) ? $metric['labels'] : []; |
69 | 69 | $labels = ['{']; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | $labels[] = '}'; |
75 | 75 | $labelStr = implode('', $labels); |
76 | - $lines[] = $metric['name'] . "$labelStr {$metric['value']}"; |
|
76 | + $lines[] = $metric['name']."$labelStr {$metric['value']}"; |
|
77 | 77 | } |
78 | 78 | return implode("\n", $lines); |
79 | 79 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'class' => static::class, |
22 | 22 | 'redirect' => false, |
23 | 23 | 'pipe' => 0, |
24 | - 'enable' => (bool)config('prometheus.enable', true), |
|
24 | + 'enable' => (bool) config('prometheus.enable', true), |
|
25 | 25 | ], |
26 | 26 | ]; |
27 | 27 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $taskWorkerNum = isset($swoole->setting['task_worker_num']) ? $swoole->setting['task_worker_num'] : 0; |
39 | 39 | $totalNum = $workerNum + $taskWorkerNum - 1; |
40 | 40 | $workerIds = range(0, $totalNum); |
41 | - $runJob = function () use ($swoole, $workerIds, $processCollector, $swooleStatsCollector, $systemCollector) { |
|
41 | + $runJob = function() use ($swoole, $workerIds, $processCollector, $swooleStatsCollector, $systemCollector) { |
|
42 | 42 | // Collect the metrics of Swoole stats() |
43 | 43 | $swooleStatsCollector->collect(); |
44 | 44 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'class' => static::class, |
22 | 22 | 'redirect' => false, |
23 | 23 | 'pipe' => 0, |
24 | - 'enable' => (bool)getenv('ENABLE_APOLLO'), |
|
24 | + 'enable' => (bool) getenv('ENABLE_APOLLO'), |
|
25 | 25 | ], |
26 | 26 | ]; |
27 | 27 | } |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | { |
31 | 31 | $filename = base_path('.env'); |
32 | 32 | if (isset($_ENV['_ENV'])) { |
33 | - $filename .= '.' . $_ENV['_ENV']; |
|
33 | + $filename .= '.'.$_ENV['_ENV']; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | self::$apollo = Client::createFromEnv(); |
37 | - self::$apollo->startWatchNotification(function (array $notifications) use ($process, $filename) { |
|
37 | + self::$apollo->startWatchNotification(function(array $notifications) use ($process, $filename) { |
|
38 | 38 | $configs = self::$apollo->pullAllAndSave($filename); |
39 | 39 | app('log')->info('[ApolloProcess] Pull all configurations', $configs); |
40 | 40 | Portal::runLaravelSCommand(base_path(), 'reload'); |
@@ -15,31 +15,31 @@ |
||
15 | 15 | public function boot() |
16 | 16 | { |
17 | 17 | $this->publishes([ |
18 | - __DIR__ . '/../../../config/prometheus.php' => base_path('config/prometheus.php'), |
|
18 | + __DIR__.'/../../../config/prometheus.php' => base_path('config/prometheus.php'), |
|
19 | 19 | ]); |
20 | 20 | } |
21 | 21 | |
22 | 22 | public function register() |
23 | 23 | { |
24 | 24 | $this->mergeConfigFrom( |
25 | - __DIR__ . '/../../../config/prometheus.php', 'prometheus' |
|
25 | + __DIR__.'/../../../config/prometheus.php', 'prometheus' |
|
26 | 26 | ); |
27 | - $this->app->singleton(RequestMiddleware::class, function ($app) { |
|
27 | + $this->app->singleton(RequestMiddleware::class, function($app) { |
|
28 | 28 | return new RequestMiddleware($app->make(HttpRequestCollector::class)); |
29 | 29 | }); |
30 | - $this->app->singleton(HttpRequestCollector::class, function ($app) { |
|
30 | + $this->app->singleton(HttpRequestCollector::class, function($app) { |
|
31 | 31 | return new HttpRequestCollector($app['config']->get('prometheus')); |
32 | 32 | }); |
33 | - $this->app->singleton(SwooleProcessCollector::class, function ($app) { |
|
33 | + $this->app->singleton(SwooleProcessCollector::class, function($app) { |
|
34 | 34 | return new SwooleProcessCollector($app['config']->get('prometheus')); |
35 | 35 | }); |
36 | - $this->app->singleton(SwooleStatsCollector::class, function ($app) { |
|
36 | + $this->app->singleton(SwooleStatsCollector::class, function($app) { |
|
37 | 37 | return new SwooleStatsCollector($app['config']->get('prometheus')); |
38 | 38 | }); |
39 | - $this->app->singleton(SystemCollector::class, function ($app) { |
|
39 | + $this->app->singleton(SystemCollector::class, function($app) { |
|
40 | 40 | return new SystemCollector($app['config']->get('prometheus')); |
41 | 41 | }); |
42 | - $this->app->singleton(Exporter::class, function ($app) { |
|
42 | + $this->app->singleton(Exporter::class, function($app) { |
|
43 | 43 | return new Exporter($app['config']->get('prometheus')); |
44 | 44 | }); |
45 | 45 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | if ($delay < 0) { |
29 | 29 | throw new \InvalidArgumentException('The delay must be greater than or equal to 0'); |
30 | 30 | } |
31 | - $this->delay = (int)$delay; |
|
31 | + $this->delay = (int) $delay; |
|
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | if ($tries < 1) { |
52 | 52 | throw new \InvalidArgumentException('The number of attempts must be greater than or equal to 1'); |
53 | 53 | } |
54 | - $this->tries = (int)$tries; |
|
54 | + $this->tries = (int) $tries; |
|
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | static $dispatch; |
75 | 75 | if (!$dispatch) { |
76 | - $dispatch = static function ($task) { |
|
76 | + $dispatch = static function($task) { |
|
77 | 77 | /**@var \Swoole\Http\Server $swoole */ |
78 | 78 | $swoole = app('swoole'); |
79 | 79 | // The worker_id of timer process is -1 |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | $ip = isset($conf['listen_ip']) ? $conf['listen_ip'] : '127.0.0.1'; |
40 | 40 | $port = isset($conf['listen_port']) ? $conf['listen_port'] : 5200; |
41 | - $socketType = isset($conf['socket_type']) ? (int)$conf['socket_type'] : SWOOLE_SOCK_TCP; |
|
41 | + $socketType = isset($conf['socket_type']) ? (int) $conf['socket_type'] : SWOOLE_SOCK_TCP; |
|
42 | 42 | |
43 | 43 | if ($socketType === SWOOLE_SOCK_UNIX_STREAM) { |
44 | 44 | $socketDir = dirname($ip); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | protected function triggerWebSocketEvent($event, array $params) |
102 | 102 | { |
103 | - return $this->callWithCatchException(function () use ($event, $params) { |
|
103 | + return $this->callWithCatchException(function() use ($event, $params) { |
|
104 | 104 | $handler = $this->getWebSocketHandler(); |
105 | 105 | |
106 | 106 | if (method_exists($handler, $event)) { |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | protected function bindWebSocketEvents() |
116 | 116 | { |
117 | 117 | if ($this->enableWebSocket) { |
118 | - $this->swoole->on('HandShake', function () { |
|
118 | + $this->swoole->on('HandShake', function() { |
|
119 | 119 | return $this->triggerWebSocketEvent('onHandShake', func_get_args()); |
120 | 120 | }); |
121 | 121 | |
122 | - $this->swoole->on('Open', function () { |
|
122 | + $this->swoole->on('Open', function() { |
|
123 | 123 | $this->triggerWebSocketEvent('onOpen', func_get_args()); |
124 | 124 | }); |
125 | 125 | |
126 | - $this->swoole->on('Message', function () { |
|
126 | + $this->swoole->on('Message', function() { |
|
127 | 127 | $this->triggerWebSocketEvent('onMessage', func_get_args()); |
128 | 128 | }); |
129 | 129 | |
130 | - $this->swoole->on('Close', function (WebSocketServer $server, $fd, $reactorId) { |
|
130 | + $this->swoole->on('Close', function(WebSocketServer $server, $fd, $reactorId) { |
|
131 | 131 | $clientInfo = $server->getClientInfo($fd); |
132 | 132 | if (isset($clientInfo['websocket_status']) && $clientInfo['websocket_status'] === \WEBSOCKET_STATUS_FRAME) { |
133 | 133 | $this->triggerWebSocketEvent('onClose', func_get_args()); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | protected function triggerPortEvent(Port $port, $handlerClass, $event, array $params) |
141 | 141 | { |
142 | - return $this->callWithCatchException(function () use ($port, $handlerClass, $event, $params) { |
|
142 | + return $this->callWithCatchException(function() use ($port, $handlerClass, $event, $params) { |
|
143 | 143 | $handler = $this->getSocketHandler($port, $handlerClass); |
144 | 144 | |
145 | 145 | if (method_exists($handler, $event)) { |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | 'BufferEmpty', |
185 | 185 | ]; |
186 | 186 | foreach ($events as $event) { |
187 | - $port->on($event, function () use ($port, $handlerClass, $event) { |
|
188 | - $this->triggerPortEvent($port, $handlerClass, 'on' . $event, func_get_args()); |
|
187 | + $port->on($event, function() use ($port, $handlerClass, $event) { |
|
188 | + $this->triggerPortEvent($port, $handlerClass, 'on'.$event, func_get_args()); |
|
189 | 189 | }); |
190 | 190 | } |
191 | 191 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | protected function bindSwooleTables() |
226 | 226 | { |
227 | - $tables = isset($this->conf['swoole_tables']) ? (array)$this->conf['swoole_tables'] : []; |
|
227 | + $tables = isset($this->conf['swoole_tables']) ? (array) $this->conf['swoole_tables'] : []; |
|
228 | 228 | foreach ($tables as $name => $table) { |
229 | 229 | $t = new Table($table['size']); |
230 | 230 | foreach ($table['column'] as $column) { |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $headers = [ |
324 | 324 | 'Upgrade' => 'websocket', |
325 | 325 | 'Connection' => 'Upgrade', |
326 | - 'Sec-WebSocket-Accept' => base64_encode(sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)), |
|
326 | + 'Sec-WebSocket-Accept' => base64_encode(sha1($secKey.'258EAFA5-E914-47DA-95CA-C5AB0DC85B11', true)), |
|
327 | 327 | 'Sec-WebSocket-Version' => '13', |
328 | 328 | ]; |
329 | 329 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | throw new \InvalidArgumentException(sprintf('%s must extend the abstract class %s', $listenerClass, Listener::class)); |
371 | 371 | } |
372 | 372 | |
373 | - $result = $this->callWithCatchException(function () use ($listener, $event) { |
|
373 | + $result = $this->callWithCatchException(function() use ($listener, $event) { |
|
374 | 374 | return $listener->handle($event); |
375 | 375 | }, [], $event->getTries()); |
376 | 376 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | protected function handleTask(Task $task) |
384 | 384 | { |
385 | - return $this->callWithCatchException(function () use ($task) { |
|
385 | + return $this->callWithCatchException(function() use ($task) { |
|
386 | 386 | $task->handle(); |
387 | 387 | return true; |
388 | 388 | }, [], $task->getTries()); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | protected function fireEvent($event, $interface, array $arguments) |
392 | 392 | { |
393 | 393 | if (isset($this->conf['event_handlers'][$event])) { |
394 | - $eventHandlers = (array)$this->conf['event_handlers'][$event]; |
|
394 | + $eventHandlers = (array) $this->conf['event_handlers'][$event]; |
|
395 | 395 | foreach ($eventHandlers as $eventHandler) { |
396 | 396 | if (!isset(class_implements($eventHandler)[$interface])) { |
397 | 397 | throw new \InvalidArgumentException(sprintf( |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | ) |
402 | 402 | ); |
403 | 403 | } |
404 | - $this->callWithCatchException(function () use ($eventHandler, $arguments) { |
|
404 | + $this->callWithCatchException(function() use ($eventHandler, $arguments) { |
|
405 | 405 | call_user_func_array([(new $eventHandler), 'handle'], $arguments); |
406 | 406 | }); |
407 | 407 | } |