@@ -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 | |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | $worker->getInputChannel()->close(); |
142 | 142 | $worker->getOutputChannel()->close(); |
143 | 143 | // open brand new channels |
144 | - $worker->setInputChannel(new SharedMemory((int)'1'.hexdec($worker->getInstance()->getId()))) |
|
145 | - ->setOutputChannel(new SharedMemory((int)'2'.hexdec($worker->getInstance()->getId()))); |
|
144 | + $worker->setInputChannel(new SharedMemory((int) '1'.hexdec($worker->getInstance()->getId()))) |
|
145 | + ->setOutputChannel(new SharedMemory((int) '2'.hexdec($worker->getInstance()->getId()))); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // fork worker |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | public function stop($name = null) { |
197 | 197 | |
198 | - foreach ($this->data as $wname => $worker) { |
|
198 | + foreach ( $this->data as $wname => $worker ) { |
|
199 | 199 | |
200 | 200 | $wpid = $worker->getPid(); |
201 | 201 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | // try to gently ask the worker to close |
208 | 208 | $worker->getOutputChannel()->send('stop'); |
209 | 209 | |
210 | - while (time() < $time) { |
|
210 | + while ( time() < $time ) { |
|
211 | 211 | |
212 | 212 | if ( !$this->running($wpid) ) break; |
213 | 213 | usleep(20000); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $worker->getOutputChannel()->close(); |
220 | 220 | |
221 | 221 | // terminate the worker if still alive |
222 | - if ($this->running($wpid)) ProcessTools::term($wpid, 5, SIGTERM); |
|
222 | + if ( $this->running($wpid) ) ProcessTools::term($wpid, 5, SIGTERM); |
|
223 | 223 | |
224 | 224 | } |
225 | 225 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | if ( empty($name) ) { |
233 | 233 | $result = []; |
234 | - foreach ($this->data as $name => $worker) { |
|
234 | + foreach ( $this->data as $name => $worker ) { |
|
235 | 235 | $result[$name] = $worker->getOutputChannel()->send('pause') > 0; |
236 | 236 | } |
237 | 237 | return $result; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | if ( empty($name) ) { |
247 | 247 | $result = []; |
248 | - foreach ($this->data as $name => $worker) { |
|
248 | + foreach ( $this->data as $name => $worker ) { |
|
249 | 249 | $result[$name] = $worker->getOutputChannel()->send('resume') > 0; |
250 | 250 | } |
251 | 251 | return $result; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | if ( $name === null ) { |
267 | 267 | |
268 | 268 | $result = []; |
269 | - foreach ($this->data as $name => $worker) { |
|
269 | + foreach ( $this->data as $name => $worker ) { |
|
270 | 270 | $result[$name] = $this->getStatus($worker); |
271 | 271 | } |
272 | 272 | 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); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | do { |
171 | 171 | $this->loop(); |
172 | - } while ($this->active); |
|
172 | + } while ( $this->active ); |
|
173 | 173 | |
174 | 174 | } catch (Exception $e) { |
175 | 175 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | $select = @socket_select($sockets, $write, $except, $this->timeout); |
207 | 207 | |
208 | - if ($select === false) { |
|
208 | + if ( $select === false ) { |
|
209 | 209 | |
210 | 210 | if ( $this->checkSocketError() && $this->active ) { |
211 | 211 | $this->logger->debug("Socket reset due to incoming signal"); |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | |
220 | 220 | } |
221 | 221 | |
222 | - if( $select < 1 ) { |
|
222 | + if ( $select < 1 ) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
226 | - if( in_array($this->socket, $sockets) ) { |
|
226 | + if ( in_array($this->socket, $sockets) ) { |
|
227 | 227 | |
228 | - for ($i=0; $i < $select; $i++) { |
|
228 | + for ( $i = 0; $i < $select; $i++ ) { |
|
229 | 229 | |
230 | 230 | if ( empty($this->connections[$i]) ) { |
231 | 231 | |
@@ -251,17 +251,17 @@ discard block |
||
251 | 251 | |
252 | 252 | } |
253 | 253 | |
254 | - for ($i = 0; $i < $this->max_connections; $i++) { |
|
254 | + for ( $i = 0; $i < $this->max_connections; $i++ ) { |
|
255 | 255 | |
256 | - if (isset($this->connections[$i])) { |
|
256 | + if ( isset($this->connections[$i]) ) { |
|
257 | 257 | |
258 | 258 | $client = $this->connections[$i]; |
259 | 259 | |
260 | - if (in_array($client->getSocket(), $sockets)) { |
|
260 | + if ( in_array($client->getSocket(), $sockets) ) { |
|
261 | 261 | |
262 | 262 | $message = $this->read($client); |
263 | 263 | |
264 | - if ($message === null) { |
|
264 | + if ( $message === null ) { |
|
265 | 265 | // if ($message == null) { |
266 | 266 | $this->hangup($client); |
267 | 267 | } else if ( $message === false ) { |
@@ -293,16 +293,16 @@ discard block |
||
293 | 293 | $datagram = ''; |
294 | 294 | $socket = $connection->getSocket(); |
295 | 295 | |
296 | - while (true) { |
|
296 | + while ( true ) { |
|
297 | 297 | $recv = @socket_read($socket, $this->read_buffer, PHP_NORMAL_READ); |
298 | 298 | if ( $recv === false ) return null; |
299 | 299 | $datagram .= $recv; |
300 | - if (empty($recv) || strstr($recv, PHP_EOL)) break; |
|
300 | + if ( empty($recv) || strstr($recv, PHP_EOL) ) break; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | $datagram = trim($datagram); |
304 | 304 | |
305 | - if ( !empty($datagram) && $datagram !== false) { |
|
305 | + if ( !empty($datagram) && $datagram !== false ) { |
|
306 | 306 | |
307 | 307 | $message = new Request(); |
308 | 308 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | |
324 | 324 | $response = new Response(); |
325 | 325 | |
326 | - if ( $request->content_type == 'application/json') { |
|
326 | + if ( $request->content_type == 'application/json' ) { |
|
327 | 327 | $this->rpc_server->setProtocol(RpcServer::JSONRPC); |
328 | 328 | } |
329 | 329 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | |
353 | 353 | $this->logger->debug("Opening connection ($idx), sending greeter"); |
354 | 354 | |
355 | - $this->events->emit( new SocketEvent('client.connect', $this->process) ); |
|
355 | + $this->events->emit(new SocketEvent('client.connect', $this->process)); |
|
356 | 356 | |
357 | 357 | $message = new Greeter(); |
358 | 358 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $this->connections[$index]->destroy(); |
372 | 372 | unset($this->connections[$index]); |
373 | 373 | |
374 | - $this->events->emit( new SocketEvent('client.hangup', $this->process) ); |
|
374 | + $this->events->emit(new SocketEvent('client.hangup', $this->process)); |
|
375 | 375 | |
376 | 376 | } |
377 | 377 |
@@ -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 |