@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | private $id; |
34 | 34 | |
35 | - public function __construct($name=null) { |
|
35 | + public function __construct($name = null) { |
|
36 | 36 | |
37 | 37 | $this->id = uniqid(); |
38 | 38 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | $this->events = $worker->getInstance()->getEvents(); |
51 | 51 | |
52 | - $this->looptime = DataFilter::filterInteger($worker->getLooptime(), $min=1, $max=PHP_INT_MAX, $default=1); |
|
52 | + $this->looptime = DataFilter::filterInteger($worker->getLooptime(), $min = 1, $max = PHP_INT_MAX, $default = 1); |
|
53 | 53 | |
54 | 54 | $this->events->subscribe('daemon.worker.stop', '\Comodojo\Daemon\Listeners\StopWorker'); |
55 | 55 | $this->events->subscribe('daemon.worker.pause', '\Comodojo\Daemon\Listeners\PauseWorker'); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | // start looping |
75 | 75 | $this->setStatus(self::LOOPING); |
76 | - while ($this->active) { |
|
76 | + while ( $this->active ) { |
|
77 | 77 | |
78 | 78 | if ( $this->paused ) { |
79 | 79 | $this->setStatus(self::PAUSED); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | $start = microtime(true); |
87 | 87 | |
88 | - $this->events->emit( new WorkerEvent('loopstart', $this, $this->worker) ); |
|
88 | + $this->events->emit(new WorkerEvent('loopstart', $this, $this->worker)); |
|
89 | 89 | |
90 | 90 | $this->worker->getInstance()->loop(); |
91 | 91 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | $elapsed = (microtime(true) - $start); |
95 | 95 | |
96 | - $this->events->emit( new WorkerEvent('loopstop', $this, $this->worker) ); |
|
96 | + $this->events->emit(new WorkerEvent('loopstop', $this, $this->worker)); |
|
97 | 97 | |
98 | 98 | $lefttime = $this->looptime - $elapsed; |
99 | 99 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $signal = $this->worker->getOutputChannel()->read(); |
140 | 140 | |
141 | 141 | if ( !empty($signal) ) { |
142 | - $this->events->emit( new WorkerEvent($signal, $this, $this->worker) ); |
|
142 | + $this->events->emit(new WorkerEvent($signal, $this, $this->worker)); |
|
143 | 143 | $this->worker->getOutputChannel()->delete(); |
144 | 144 | } |
145 | 145 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * THE SOFTWARE. |
30 | 30 | */ |
31 | 31 | |
32 | - class Manager implements Iterator, Countable { |
|
32 | + class Manager implements Iterator, Countable { |
|
33 | 33 | |
34 | 34 | use IteratorTrait; |
35 | 35 | use CountableTrait; |
@@ -274,4 +274,4 @@ discard block |
||
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | - } |
|
277 | + } |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | ->setInstance($worker) |
94 | 94 | ->setLooptime($looptime) |
95 | 95 | ->setForever($forever) |
96 | - ->setInputChannel(new SharedMemory((int)'1'.hexdec($worker->getId()))) |
|
97 | - ->setOutputChannel(new SharedMemory((int)'2'.hexdec($worker->getId()))); |
|
96 | + ->setInputChannel(new SharedMemory((int) '1'.hexdec($worker->getId()))) |
|
97 | + ->setOutputChannel(new SharedMemory((int) '2'.hexdec($worker->getId()))); |
|
98 | 98 | |
99 | 99 | $this->data[$name] = $w; |
100 | 100 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | public function stop($name = null) { |
186 | 186 | |
187 | - foreach ($this->data as $wname => $worker) { |
|
187 | + foreach ( $this->data as $wname => $worker ) { |
|
188 | 188 | |
189 | 189 | $wpid = $worker->getPid(); |
190 | 190 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | // try to gently ask the worker to close |
197 | 197 | $worker->getOutputChannel()->send('stop'); |
198 | 198 | |
199 | - while (time() < $time) { |
|
199 | + while ( time() < $time ) { |
|
200 | 200 | |
201 | 201 | if ( !$this->running($wpid) ) break; |
202 | 202 | usleep(20000); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $worker->getOutputChannel()->close(); |
209 | 209 | |
210 | 210 | // terminate the worker if still alive |
211 | - if ($this->running($wpid)) ProcessTools::term($wpid, 5, SIGTERM); |
|
211 | + if ( $this->running($wpid) ) ProcessTools::term($wpid, 5, SIGTERM); |
|
212 | 212 | |
213 | 213 | } |
214 | 214 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | if ( empty($name) ) { |
222 | 222 | $result = []; |
223 | - foreach ($this->data as $name => $worker) { |
|
223 | + foreach ( $this->data as $name => $worker ) { |
|
224 | 224 | $result[$name] = $worker->getOutputChannel()->send('pause') > 0; |
225 | 225 | } |
226 | 226 | return $result; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | |
235 | 235 | if ( empty($name) ) { |
236 | 236 | $result = []; |
237 | - foreach ($this->data as $name => $worker) { |
|
237 | + foreach ( $this->data as $name => $worker ) { |
|
238 | 238 | $result[$name] = $worker->getOutputChannel()->send('resume') > 0; |
239 | 239 | } |
240 | 240 | return $result; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | if ( $name === null ) { |
256 | 256 | |
257 | 257 | $result = []; |
258 | - foreach ($this->data as $name => $worker) { |
|
258 | + foreach ( $this->data as $name => $worker ) { |
|
259 | 259 | $result[$name] = $this->getStatus($worker); |
260 | 260 | } |
261 | 261 | return $result; |
@@ -46,7 +46,7 @@ |
||
46 | 46 | |
47 | 47 | public function delete() { |
48 | 48 | |
49 | - return shmop_write($this->key, str_pad('',128), 0); |
|
49 | + return shmop_write($this->key, str_pad('', 128), 0); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | $workers = $daemon->getWorkers(); |
29 | 29 | $logger = $daemon->getLogger(); |
30 | 30 | |
31 | - foreach ($workers as $name => $worker) { |
|
31 | + foreach ( $workers as $name => $worker ) { |
|
32 | 32 | |
33 | - if ($workers->running($worker->getPid())) { |
|
33 | + if ( $workers->running($worker->getPid()) ) { |
|
34 | 34 | |
35 | 35 | $logger->debug("Worker $name seems to be running"); |
36 | 36 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | $logger->warning("Worker $name has exited"); |
40 | 40 | |
41 | - if ($worker->getForever()) { |
|
41 | + if ( $worker->getForever() ) { |
|
42 | 42 | $logger->warning("Attempting to restart $name"); |
43 | 43 | $workers->start($name, true); |
44 | 44 | } else { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @property LoggerInterface $logger |
68 | 68 | * @property int $pid |
69 | 69 | */ |
70 | - public function __construct($properties = [], LoggerInterface $logger = null, EventsManager $events = null){ |
|
70 | + public function __construct($properties = [], LoggerInterface $logger = null, EventsManager $events = null) { |
|
71 | 71 | |
72 | 72 | if ( !Checks::multithread() ) { |
73 | 73 | throw new Exception("Missing pcntl fork"); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $this->console = new CLImate(); |
99 | 99 | $this->console->description($properties->description); |
100 | 100 | $args = new $properties->arguments; |
101 | - $this->console->arguments->add( $args::create()->export() ); |
|
101 | + $this->console->arguments->add($args::create()->export()); |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | $this->setup(); |
186 | 186 | |
187 | - foreach ($this->workers as $name => $worker) { |
|
187 | + foreach ( $this->workers as $name => $worker ) { |
|
188 | 188 | |
189 | 189 | $this->workers->start($name); |
190 | 190 | |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | |
304 | 304 | private function detach() { |
305 | 305 | |
306 | - if (is_resource(STDOUT)) fclose(STDOUT); |
|
307 | - if (is_resource(STDERR)) fclose(STDERR); |
|
308 | - if (is_resource(STDIN)) fclose(STDIN); |
|
306 | + if ( is_resource(STDOUT) ) fclose(STDOUT); |
|
307 | + if ( is_resource(STDERR) ) fclose(STDERR); |
|
308 | + if ( is_resource(STDIN) ) fclose(STDIN); |
|
309 | 309 | |
310 | 310 | // become a session leader |
311 | 311 | $sid = posix_setsid(); |
@@ -67,7 +67,7 @@ |
||
67 | 67 | * @property LoggerInterface $logger |
68 | 68 | * @property int $pid |
69 | 69 | */ |
70 | - public function __construct($properties = [], LoggerInterface $logger = null, EventsManager $events = null){ |
|
70 | + public function __construct($properties = [], LoggerInterface $logger = null, EventsManager $events = null) { |
|
71 | 71 | |
72 | 72 | if ( !Checks::multithread() ) { |
73 | 73 | throw new Exception("Missing pcntl fork"); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param LoggerInterface $logger; |
45 | 45 | * @param EventsManager $events; |
46 | 46 | */ |
47 | - public function __construct($niceness = null, LoggerInterface $logger = null, EventsManager $events = null){ |
|
47 | + public function __construct($niceness = null, LoggerInterface $logger = null, EventsManager $events = null) { |
|
48 | 48 | |
49 | 49 | if ( !Checks::cli() ) { |
50 | 50 | throw new RuntimeException("Process can run only in cli SAPI"); |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | |
87 | 87 | $this->logger->debug("Received $signame ($signal) signal, firing associated event(s)"); |
88 | 88 | |
89 | - $this->events->emit( new PosixEvent($signal, $this) ); |
|
90 | - $this->events->emit( new PosixEvent($signame, $this) ); |
|
89 | + $this->events->emit(new PosixEvent($signal, $this)); |
|
90 | + $this->events->emit(new PosixEvent($signame, $this)); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 |
@@ -44,7 +44,7 @@ |
||
44 | 44 | * @param LoggerInterface $logger; |
45 | 45 | * @param EventsManager $events; |
46 | 46 | */ |
47 | - public function __construct($niceness = null, LoggerInterface $logger = null, EventsManager $events = null){ |
|
47 | + public function __construct($niceness = null, LoggerInterface $logger = null, EventsManager $events = null) { |
|
48 | 48 | |
49 | 49 | if ( !Checks::cli() ) { |
50 | 50 | throw new RuntimeException("Process can run only in cli SAPI"); |
@@ -288,9 +288,9 @@ |
||
288 | 288 | |
289 | 289 | if ($message === null) { |
290 | 290 | // if ($message == null) { |
291 | - $this->hangup($client); |
|
291 | + $this->hangup($client); |
|
292 | 292 | } else if ( $message === false ) { |
293 | - continue; |
|
293 | + continue; |
|
294 | 294 | } else { |
295 | 295 | $output = $this->serve($message); |
296 | 296 | $this->write($client, $output); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | do { |
166 | 166 | $this->loop(); |
167 | - } while ($this->active); |
|
167 | + } while ( $this->active ); |
|
168 | 168 | |
169 | 169 | } catch (Exception $e) { |
170 | 170 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | $select = @socket_select($sockets, $write, $except, $this->timeout); |
208 | 208 | |
209 | - if ($select === false) { |
|
209 | + if ( $select === false ) { |
|
210 | 210 | |
211 | 211 | if ( $this->checkSocketError() && $this->active ) { |
212 | 212 | $this->logger->debug("Socket reset due to incoming signal"); |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | |
221 | 221 | } |
222 | 222 | |
223 | - if( $select < 1 ) { |
|
223 | + if ( $select < 1 ) { |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | |
227 | - if( in_array($this->socket, $sockets) ) { |
|
227 | + if ( in_array($this->socket, $sockets) ) { |
|
228 | 228 | |
229 | - for ($i=0; $i < $select; $i++) { |
|
229 | + for ( $i = 0; $i < $select; $i++ ) { |
|
230 | 230 | |
231 | 231 | if ( empty($this->connections[$i]) ) { |
232 | 232 | |
@@ -276,17 +276,17 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | - for ($i = 0; $i < $this->max_connections; $i++) { |
|
279 | + for ( $i = 0; $i < $this->max_connections; $i++ ) { |
|
280 | 280 | |
281 | - if (isset($this->connections[$i])) { |
|
281 | + if ( isset($this->connections[$i]) ) { |
|
282 | 282 | |
283 | 283 | $client = $this->connections[$i]; |
284 | 284 | |
285 | - if (in_array($client->getSocket(), $sockets)) { |
|
285 | + if ( in_array($client->getSocket(), $sockets) ) { |
|
286 | 286 | |
287 | 287 | $message = $this->read($client); |
288 | 288 | |
289 | - if ($message === null) { |
|
289 | + if ( $message === null ) { |
|
290 | 290 | // if ($message == null) { |
291 | 291 | $this->hangup($client); |
292 | 292 | } else if ( $message === false ) { |
@@ -318,18 +318,18 @@ discard block |
||
318 | 318 | $datagram = ''; |
319 | 319 | $socket = $connection->getSocket(); |
320 | 320 | |
321 | - while (true) { |
|
321 | + while ( true ) { |
|
322 | 322 | $recv = @socket_read($socket, $this->read_buffer, PHP_NORMAL_READ); |
323 | 323 | // if ( $recv === false ) break; |
324 | 324 | // if ( $recv === 0 ) return null; |
325 | 325 | if ( $recv === false ) return null; |
326 | 326 | $datagram .= $recv; |
327 | - if (empty($recv) || strstr($recv, PHP_EOL)) break; |
|
327 | + if ( empty($recv) || strstr($recv, PHP_EOL) ) break; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | $datagram = trim($datagram); |
331 | 331 | |
332 | - if ( !empty($datagram) && $datagram !== false) { |
|
332 | + if ( !empty($datagram) && $datagram !== false ) { |
|
333 | 333 | |
334 | 334 | $message = new Request(); |
335 | 335 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | |
352 | 352 | $response = new Response(); |
353 | 353 | |
354 | - if ( $request->content_type == 'application/json') { |
|
354 | + if ( $request->content_type == 'application/json' ) { |
|
355 | 355 | $this->rpc_server->setProtocol(RpcServer::JSONRPC); |
356 | 356 | } |
357 | 357 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | |
411 | 411 | $this->logger->debug("Opening connection ($idx), sending greeter"); |
412 | 412 | |
413 | - $this->events->emit( new SocketEvent('client.connect', $this->process) ); |
|
413 | + $this->events->emit(new SocketEvent('client.connect', $this->process)); |
|
414 | 414 | |
415 | 415 | $message = new Greeter(); |
416 | 416 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $this->connections[$index]->destroy(); |
430 | 430 | unset($this->connections[$index]); |
431 | 431 | |
432 | - $this->events->emit( new SocketEvent('client.hangup', $this->process) ); |
|
432 | + $this->events->emit(new SocketEvent('client.hangup', $this->process)); |
|
433 | 433 | |
434 | 434 | } |
435 | 435 |
@@ -238,7 +238,7 @@ |
||
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | - * Check if an encrypted envelope is consisent or not |
|
241 | + * Check if an encrypted envelope is consisent or not |
|
242 | 242 | * |
243 | 243 | * @param string $data |
244 | 244 | * |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | LoggerInterface $logger, |
20 | 20 | $data, |
21 | 21 | $content_type, |
22 | - $encrypt=false |
|
22 | + $encrypt = false |
|
23 | 23 | ) { |
24 | 24 | |
25 | 25 | try { |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | |
188 | 188 | $datagram = ''; |
189 | 189 | |
190 | - while (true) { |
|
190 | + while ( true ) { |
|
191 | 191 | $recv = @socket_read($this->socket, $this->read_buffer, PHP_NORMAL_READ); |
192 | 192 | if ( $recv === false ) break; |
193 | 193 | if ( $recv === 0 ) return null; |
194 | 194 | $datagram .= $recv; |
195 | - if(strstr($recv, PHP_EOL)) break; |
|
195 | + if ( strstr($recv, PHP_EOL) ) break; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return trim($datagram); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | $this->aes->setKey($key); |
209 | 209 | |
210 | - $return = 'comodojo_encrypted_request-'.base64_encode( $this->aes->encrypt($data) ); |
|
210 | + $return = 'comodojo_encrypted_request-'.base64_encode($this->aes->encrypt($data)); |
|
211 | 211 | |
212 | 212 | } else { |
213 | 213 |