@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Bind socket |
14 | - * @return boolean Success. |
|
14 | + * @return null|boolean Success. |
|
15 | 15 | */ |
16 | 16 | public function bind() { |
17 | 17 | $e = explode(':', $this->addr, 4); |
@@ -19,8 +19,7 @@ |
||
19 | 19 | $user = $e[0]; |
20 | 20 | $group = $e[1]; |
21 | 21 | $path = $e[2]; |
22 | - } |
|
23 | - elseif (sizeof($e) == 2) { |
|
22 | + } elseif (sizeof($e) == 2) { |
|
24 | 23 | $user = $e[0]; |
25 | 24 | $group = FALSE; |
26 | 25 | $path = $e[1]; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | /** |
89 | 89 | * Setting default config options |
90 | - * @return array|false |
|
90 | + * @return boolean |
|
91 | 91 | */ |
92 | 92 | protected function getConfigDefaults() { |
93 | 93 | return false; |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * Bind given sockets |
247 | 247 | * @param mixed Addresses to bind |
248 | 248 | * @param boolean SO_REUSE. Default is true |
249 | - * @return void |
|
249 | + * @return integer |
|
250 | 250 | */ |
251 | 251 | public function bind($addrs = array(), $reuse = true, $max = 0) { |
252 | 252 | if (is_string($addrs)) { |
@@ -314,6 +314,8 @@ discard block |
||
314 | 314 | * @param string Optional. Default port |
315 | 315 | * @param callback Optional. Callback. |
316 | 316 | * @param string Optional. Connection class name. |
317 | + * @param string $addr |
|
318 | + * @param Closure $cb |
|
317 | 319 | * @return integer Connection's ID. Boolean false when failed. |
318 | 320 | */ |
319 | 321 | public function connectTo($addr, $port = 0, $cb = null, $class = null) { |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * Called when the worker is ready to go. |
41 | 41 | * @return void |
42 | - */ |
|
42 | + */ |
|
43 | 43 | public function onReady() { |
44 | 44 | $this->enable(); |
45 | 45 | } |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | |
120 | 120 | |
121 | 121 | /** |
122 | - * Process default config |
|
123 | - * @todo move it to Daemon_Config class |
|
124 | - * @param array {"setting": "value"} |
|
125 | - * @return void |
|
126 | - */ |
|
122 | + * Process default config |
|
123 | + * @todo move it to Daemon_Config class |
|
124 | + * @param array {"setting": "value"} |
|
125 | + * @return void |
|
126 | + */ |
|
127 | 127 | public function processDefaultConfig($settings = array()) { |
128 | 128 | foreach ($settings as $k => $v) { |
129 | 129 | $k = strtolower(str_replace('-', '', $k)); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * Enable socket events |
160 | 160 | * @return void |
161 | - */ |
|
161 | + */ |
|
162 | 162 | public function enable() { |
163 | 163 | if ($this->enabled) { |
164 | 164 | return; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class ConnectionPool extends ObjectStorage { |
11 | 11 | |
12 | - public $allowedClients = null; |
|
12 | + public $allowedClients = null; |
|
13 | 13 | public $connectionClass; |
14 | 14 | public $name; |
15 | 15 | public $config; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if (isset(self::$instances[$key])) { |
104 | 104 | return self::$instances[$key]; |
105 | 105 | } |
106 | - $k = 'Pool:' . $class . ($arg !== '' ? ':' . $arg : '' ); |
|
106 | + $k = 'Pool:' . $class . ($arg !== '' ? ':' . $arg : ''); |
|
107 | 107 | |
108 | 108 | $config = (isset(Daemon::$config->{$k}) && Daemon::$config->{$k} instanceof Daemon_ConfigSection) ? Daemon::$config->{$k}: new Daemon_ConfigSection; |
109 | 109 | $obj = self::$instances[$key] = new $class($config); |
@@ -129,16 +129,16 @@ discard block |
||
129 | 129 | $k = strtolower(str_replace('-', '', $k)); |
130 | 130 | |
131 | 131 | if (!isset($this->config->{$k})) { |
132 | - if (is_scalar($v)) { |
|
132 | + if (is_scalar($v)) { |
|
133 | 133 | $this->config->{$k} = new Daemon_ConfigEntry($v); |
134 | 134 | } else { |
135 | 135 | $this->config->{$k} = $v; |
136 | 136 | } |
137 | 137 | } elseif ($v instanceof Daemon_ConfigSection) { |
138 | 138 | // @todo |
139 | - } else { |
|
139 | + } else { |
|
140 | 140 | $current = $this->config->{$k}; |
141 | - if (is_scalar($v)) { |
|
141 | + if (is_scalar($v)) { |
|
142 | 142 | $this->config->{$k} = new Daemon_ConfigEntry($v); |
143 | 143 | } else { |
144 | 144 | $this->config->{$k} = $v; |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | $socket->setDefaultPort($this->config->port->value); |
267 | 267 | } |
268 | 268 | } else { |
269 | - if (stripos($addr,'tcp://') === 0) { |
|
269 | + if (stripos($addr, 'tcp://') === 0) { |
|
270 | 270 | $addr = substr($addr, 6); |
271 | 271 | } |
272 | - elseif (stripos($addr,'tcp:') === 0) { |
|
272 | + elseif (stripos($addr, 'tcp:') === 0) { |
|
273 | 273 | $addr = substr($addr, 4); |
274 | 274 | } |
275 | 275 | $socket = new BoundTCPSocket($addr, $reuse); |
@@ -70,17 +70,13 @@ discard block |
||
70 | 70 | $k = strtolower($k); |
71 | 71 | if ($k === 'connectionclass') { |
72 | 72 | $this->connectionClass = $v; |
73 | - } |
|
74 | - elseif ($k === 'name') { |
|
73 | + } elseif ($k === 'name') { |
|
75 | 74 | $this->name = $v; |
76 | - } |
|
77 | - elseif ($k === 'allowedclients') { |
|
75 | + } elseif ($k === 'allowedclients') { |
|
78 | 76 | $this->allowedClients = $v; |
79 | - } |
|
80 | - elseif ($k === 'maxallowedpacket') { |
|
77 | + } elseif ($k === 'maxallowedpacket') { |
|
81 | 78 | $this->maxAllowedPacket = (int) $v; |
82 | - } |
|
83 | - elseif ($k === 'maxconcurrency') { |
|
79 | + } elseif ($k === 'maxconcurrency') { |
|
84 | 80 | $this->maxConcurrency = (int) $v; |
85 | 81 | } |
86 | 82 | } |
@@ -136,7 +132,7 @@ discard block |
||
136 | 132 | } |
137 | 133 | } elseif ($v instanceof Daemon_ConfigSection) { |
138 | 134 | // @todo |
139 | - } else { |
|
135 | + } else { |
|
140 | 136 | $current = $this->config->{$k}; |
141 | 137 | if (is_scalar($v)) { |
142 | 138 | $this->config->{$k} = new Daemon_ConfigEntry($v); |
@@ -268,8 +264,7 @@ discard block |
||
268 | 264 | } else { |
269 | 265 | if (stripos($addr,'tcp://') === 0) { |
270 | 266 | $addr = substr($addr, 6); |
271 | - } |
|
272 | - elseif (stripos($addr,'tcp:') === 0) { |
|
267 | + } elseif (stripos($addr,'tcp:') === 0) { |
|
273 | 268 | $addr = substr($addr, 4); |
274 | 269 | } |
275 | 270 | $socket = new BoundTCPSocket($addr, $reuse); |
@@ -82,6 +82,9 @@ discard block |
||
82 | 82 | define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
83 | 83 | } |
84 | 84 | |
85 | + /** |
|
86 | + * @param string $mod |
|
87 | + */ |
|
85 | 88 | public static function loadModuleIfAbsent($mod) { |
86 | 89 | if (extension_loaded($mod)) { |
87 | 90 | return true; |
@@ -249,7 +252,7 @@ discard block |
||
249 | 252 | |
250 | 253 | /** |
251 | 254 | * It allows to run your simple web-apps in spawn-fcgi/php-fpm environment. |
252 | - * @return boolean - Success. |
|
255 | + * @return boolean|null - Success. |
|
253 | 256 | */ |
254 | 257 | public static function compatRunEmul() { |
255 | 258 | Daemon::$dir = realpath(__DIR__ . '/..'); |
@@ -473,7 +476,7 @@ discard block |
||
473 | 476 | |
474 | 477 | /** |
475 | 478 | * spawn new master process. |
476 | - * @return boolean - success |
|
479 | + * @return null|integer - success |
|
477 | 480 | */ |
478 | 481 | public static function spawnMaster() { |
479 | 482 | Daemon::$masters->push($thread = new Daemon_MasterThread); |
@@ -542,6 +545,8 @@ discard block |
||
542 | 545 | |
543 | 546 | /** |
544 | 547 | * Calculates a difference between two dates. |
548 | + * @param integer $date_start |
|
549 | + * @param integer $date_finish |
|
545 | 550 | * @return string Something like this: 1 year. 2 mon. 6 day. 4 hours. 21 min. 10 sec. |
546 | 551 | */ |
547 | 552 | public static function date_period_text($date_start, $date_finish) { |
@@ -79,7 +79,7 @@ |
||
79 | 79 | Daemon::$reusePort = 1 === preg_match("~BSD~i", php_uname('s')); |
80 | 80 | |
81 | 81 | if (Daemon::$reusePort && !defined("SO_REUSEPORT")) |
82 | - define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
|
82 | + define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public static function loadModuleIfAbsent($mod) { |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | const SUPPORT_RUNKIT_SANDBOX = 0; |
13 | 13 | const SUPPORT_RUNKIT_MODIFY = 1; |
14 | 14 | const SUPPORT_RUNKIT_INTERNAL_MODIFY = 2; |
15 | - const SUPPORT_RUNKIT_IMPORT = 3; |
|
15 | + const SUPPORT_RUNKIT_IMPORT = 3; |
|
16 | 16 | const WSTATE_IDLE = 1; |
17 | 17 | const WSTATE_BUSY = 2; |
18 | 18 | const WSTATE_SHUTDOWN = 3; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | Daemon::$reusePort = 1 === preg_match("~BSD~i", php_uname('s')); |
80 | 80 | |
81 | 81 | if (Daemon::$reusePort && !defined("SO_REUSEPORT")) |
82 | - define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
|
82 | + define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public static function loadModuleIfAbsent($mod) { |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | |
133 | 133 | public static function uncaughtExceptionHandler(Exception $e) { |
134 | 134 | $msg = $e->getMessage(); |
135 | - Daemon::log('Uncaught '.get_class($e).' (' . $e->getCode() . ')' . (strlen($msg) ? ': ' . $msg : ''). ".\n" . $e->getTraceAsString()); |
|
135 | + Daemon::log('Uncaught ' . get_class($e) . ' (' . $e->getCode() . ')' . (strlen($msg) ? ': ' . $msg : '') . ".\n" . $e->getTraceAsString()); |
|
136 | 136 | if (Daemon::$req) { |
137 | - Daemon::$req->out('<b>Uncaught '.get_class($e).' (' . $e->getCode() . ')</b>' . (strlen($msg) ? ': ' . $msg : ''). '.<br />'); |
|
137 | + Daemon::$req->out('<b>Uncaught ' . get_class($e) . ' (' . $e->getCode() . ')</b>' . (strlen($msg) ? ': ' . $msg : '') . '.<br />'); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | E_USER_DEPRECATED => 'Deprecated (userland)', |
165 | 165 | ); |
166 | 166 | $errtype = $errtypes[$errno]; |
167 | - Daemon::log($errtype . ': '.$errstr.' in ' . $errfile . ':' . $errline . "\n" . Debug::backtrace()); |
|
167 | + Daemon::log($errtype . ': ' . $errstr . ' in ' . $errfile . ':' . $errline . "\n" . Debug::backtrace()); |
|
168 | 168 | if (Daemon::$req) { |
169 | - Daemon::$req->out('<strong>' . $errtype . '</strong>: ' . $errstr . ' in ' . basename($errfile) . ':' . $errline.'<br />'); |
|
169 | + Daemon::$req->out('<strong>' . $errtype . '</strong>: ' . $errstr . ' in ' . basename($errfile) . ':' . $errline . '<br />'); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | $req->attrs->cookie = $_REQUEST; |
291 | 291 | $req->attrs->server = $_SERVER; |
292 | 292 | $req->attrs->files = $_FILES; |
293 | - $req->attrs->session = isset($_SESSION)?$_SESSION:NULL; |
|
293 | + $req->attrs->session = isset($_SESSION) ? $_SESSION : NULL; |
|
294 | 294 | $req->attrs->connId = 1; |
295 | 295 | $req->attrs->trole = 'RESPONDER'; |
296 | 296 | $req->attrs->flags = 0; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $apaths = explode(';', $paths); |
318 | 318 | $found = false; |
319 | 319 | |
320 | - foreach($apaths as $path) { |
|
320 | + foreach ($apaths as $path) { |
|
321 | 321 | if (is_file($p = realpath($path))) { |
322 | 322 | $found = true; |
323 | 323 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | chown(Daemon::$config->logstorage->value, Daemon::$config->user->value); // @TODO: rewrite to async I/O |
356 | 356 | } |
357 | 357 | if ((Daemon::$process instanceof Daemon_WorkerThread) && FS::$supported) { |
358 | - FS::open(Daemon::$config->logstorage->value, 'a!', function ($file) { |
|
358 | + FS::open(Daemon::$config->logstorage->value, 'a!', function($file) { |
|
359 | 359 | Daemon::$logpointerAsync = $file; |
360 | 360 | if (!$file) { |
361 | 361 | return; |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | if (is_resource(STDERR)) { |
464 | 464 | fwrite(STDERR, '[PHPD] ' . $msg . "\n"); |
465 | 465 | } |
466 | - $msg = '[' . date('D, j M Y H:i:s', $mt[1]) . '.' . sprintf('%06d', $mt[0]*1000000) . ' ' . date('O') . '] ' . $msg . "\n"; |
|
466 | + $msg = '[' . date('D, j M Y H:i:s', $mt[1]) . '.' . sprintf('%06d', $mt[0] * 1000000) . ' ' . date('O') . '] ' . $msg . "\n"; |
|
467 | 467 | if (Daemon::$logpointerAsync) { |
468 | 468 | Daemon::$logpointerAsync->write($msg); |
469 | 469 | } elseif (Daemon::$logpointer) { |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | public static function date_period_text($date_start, $date_finish) { |
548 | 548 | $result = Daemon::date_period($date_start, $date_finish); |
549 | 549 | |
550 | - $str = ''; |
|
550 | + $str = ''; |
|
551 | 551 | |
552 | 552 | if ($result[5] > 0) { |
553 | 553 | $str .= $result[5] . ' year. '; |
@@ -78,8 +78,10 @@ discard block |
||
78 | 78 | // only in BSD flavour operating systems via SO_REUSEPORT socket option |
79 | 79 | Daemon::$reusePort = 1 === preg_match("~BSD~i", php_uname('s')); |
80 | 80 | |
81 | - if (Daemon::$reusePort && !defined("SO_REUSEPORT")) |
|
82 | - define("SO_REUSEPORT", 0x200); // FIXME: this is a BSD-only hack |
|
81 | + if (Daemon::$reusePort && !defined("SO_REUSEPORT")) { |
|
82 | + define("SO_REUSEPORT", 0x200); |
|
83 | + } |
|
84 | + // FIXME: this is a BSD-only hack |
|
83 | 85 | } |
84 | 86 | |
85 | 87 | public static function loadModuleIfAbsent($mod) { |
@@ -144,8 +146,7 @@ discard block |
||
144 | 146 | if (!Daemon::$restrictErrorControl) { |
145 | 147 | return; |
146 | 148 | } |
147 | - } |
|
148 | - elseif (!($l & $errno)) { |
|
149 | + } elseif (!($l & $errno)) { |
|
149 | 150 | return; |
150 | 151 | } |
151 | 152 | |
@@ -404,34 +405,28 @@ discard block |
||
404 | 405 | } |
405 | 406 | if ($code === 0) { |
406 | 407 | break 2; |
407 | - } |
|
408 | - elseif ($code === Daemon::WSTATE_IDLE) { |
|
408 | + } elseif ($code === Daemon::WSTATE_IDLE) { |
|
409 | 409 | // idle |
410 | 410 | ++$stat['alive']; |
411 | 411 | ++$stat['idle']; |
412 | - } |
|
413 | - elseif ($code === Daemon::WSTATE_BUSY) { |
|
412 | + } elseif ($code === Daemon::WSTATE_BUSY) { |
|
414 | 413 | // busy |
415 | 414 | ++$stat['alive']; |
416 | 415 | ++$stat['busy']; |
417 | - } |
|
418 | - elseif ($code === Daemon::WSTATE_SHUTDOWN) { |
|
416 | + } elseif ($code === Daemon::WSTATE_SHUTDOWN) { |
|
419 | 417 | // shutdown |
420 | 418 | ++$stat['shutdown']; |
421 | - } |
|
422 | - elseif ($code === Daemon::WSTATE_PREINIT) { |
|
419 | + } elseif ($code === Daemon::WSTATE_PREINIT) { |
|
423 | 420 | // pre-init |
424 | 421 | ++$stat['alive']; |
425 | 422 | ++$stat['preinit']; |
426 | 423 | ++$stat['idle']; |
427 | - } |
|
428 | - elseif ($code === Daemon::WSTATE_WAITINIT) { |
|
424 | + } elseif ($code === Daemon::WSTATE_WAITINIT) { |
|
429 | 425 | // wait-init |
430 | 426 | ++$stat['alive']; |
431 | 427 | ++$stat['waitinit']; |
432 | 428 | ++$stat['idle']; |
433 | - } |
|
434 | - elseif ($code === Daemon::WSTATE_INIT) { // init |
|
429 | + } elseif ($code === Daemon::WSTATE_INIT) { // init |
|
435 | 430 | ++$stat['alive']; |
436 | 431 | ++$stat['init']; |
437 | 432 | ++$stat['idle']; |
@@ -453,8 +448,7 @@ discard block |
||
453 | 448 | $args = func_get_args(); |
454 | 449 | if (sizeof($args) == 1) { |
455 | 450 | $msg = is_scalar($args[0]) ? $args[0] : Debug::dump($args[0]); |
456 | - } |
|
457 | - else { |
|
451 | + } else { |
|
458 | 452 | $msg = Debug::dump($args); |
459 | 453 | } |
460 | 454 |
@@ -499,7 +499,6 @@ |
||
499 | 499 | |
500 | 500 | /** |
501 | 501 | * Parses command-line arguments. |
502 | - * @param array $_SERVER['argv'] |
|
503 | 502 | * @return void |
504 | 503 | */ |
505 | 504 | public static function getArgs($args) { |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | |
124 | 124 | if ('log' === $runmode) { |
125 | - passthru('tail -n '.$n.' -f '.escapeshellarg(Daemon::$config->logstorage->value)); |
|
125 | + passthru('tail -n ' . $n . ' -f ' . escapeshellarg(Daemon::$config->logstorage->value)); |
|
126 | 126 | exit; |
127 | 127 | } |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | if (isset(Daemon::$config->locale->value) && Daemon::$config->locale->value !== '') { |
134 | - setlocale(LC_ALL,explode(',', Daemon::$config->locale->value)); |
|
134 | + setlocale(LC_ALL, explode(',', Daemon::$config->locale->value)); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | if ( |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | elseif ($runmode == 'reopenlog') { |
330 | 330 | if ( |
331 | 331 | (!Daemon_Bootstrap::$pid) |
332 | - || (!posix_kill(Daemon_Bootstrap::$pid,SIGUSR1)) |
|
332 | + || (!posix_kill(Daemon_Bootstrap::$pid, SIGUSR1)) |
|
333 | 333 | ) { |
334 | 334 | echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
335 | 335 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | elseif ($runmode == 'reload') { |
338 | 338 | if ( |
339 | 339 | (!Daemon_Bootstrap::$pid) |
340 | - || (!posix_kill(Daemon_Bootstrap::$pid,SIGUSR2)) |
|
340 | + || (!posix_kill(Daemon_Bootstrap::$pid, SIGUSR2)) |
|
341 | 341 | ) { |
342 | 342 | echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
343 | 343 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ); |
369 | 369 | |
370 | 370 | foreach (Daemon::$config as $name => $entry) { |
371 | - if (!$entry instanceof Daemon_ConfigEntry) {continue;} |
|
371 | + if (!$entry instanceof Daemon_ConfigEntry) {continue; } |
|
372 | 372 | |
373 | 373 | $row = array( |
374 | 374 | 'parameter' => $name, |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | elseif ($runmode == 'hardstop') { |
393 | 393 | echo '[HARDSTOP] Sending SIGINT to ' . Daemon_Bootstrap::$pid . '... '; |
394 | 394 | |
395 | - $ok = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid,SIGINT); |
|
395 | + $ok = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid, SIGINT); |
|
396 | 396 | |
397 | 397 | echo $ok ? 'OK.' : 'ERROR. It seems that phpDaemon is not running.'; |
398 | 398 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | |
438 | 438 | echo "\nAlso you can use some optional parameters to override the same configuration variables:\n"; |
439 | 439 | |
440 | - foreach(self::$params as $name => $desc) { |
|
440 | + foreach (self::$params as $name => $desc) { |
|
441 | 441 | if (empty($desc)) { |
442 | 442 | continue; |
443 | 443 | } |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * @return void |
479 | 479 | */ |
480 | 480 | public static function stop($mode = 1) { |
481 | - $ok = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid, $mode === 3 ? SIGINT:SIGTERM); |
|
481 | + $ok = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid, $mode === 3 ? SIGINT : SIGTERM); |
|
482 | 482 | |
483 | 483 | if (!$ok) { |
484 | 484 | echo '[WARN]. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | $out = array(); |
507 | 507 | $last_arg = NULL; |
508 | 508 | |
509 | - for($i = 1, $il = sizeof($args); $i < $il; ++$i) { |
|
509 | + for ($i = 1, $il = sizeof($args); $i < $il; ++$i) { |
|
510 | 510 | if (preg_match('~^--(.+)~', $args[$i], $match)) { |
511 | 511 | $parts = explode('=', $match[1]); |
512 | 512 | $key = preg_replace('~[^a-z0-9]+~', '', $parts[0]); |
@@ -90,8 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | self::printUsage(); |
92 | 92 | exit; |
93 | - } |
|
94 | - elseif ('help' === $runmode) { |
|
93 | + } elseif ('help' === $runmode) { |
|
95 | 94 | self::printHelp(); |
96 | 95 | exit; |
97 | 96 | } |
@@ -193,17 +192,14 @@ discard block |
||
193 | 192 | } |
194 | 193 | |
195 | 194 | Daemon_Bootstrap::$pid = 0; |
196 | - } |
|
197 | - elseif (!is_file(Daemon::$config->pidfile->value)) { |
|
195 | + } elseif (!is_file(Daemon::$config->pidfile->value)) { |
|
198 | 196 | Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be a regular file.'); |
199 | 197 | Daemon_Bootstrap::$pid = FALSE; |
200 | 198 | $error = true; |
201 | - } |
|
202 | - elseif (!is_writable(Daemon::$config->pidfile->value)) { |
|
199 | + } elseif (!is_writable(Daemon::$config->pidfile->value)) { |
|
203 | 200 | Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be writable.'); |
204 | 201 | $error = true; |
205 | - } |
|
206 | - elseif (!is_readable(Daemon::$config->pidfile->value)) { |
|
202 | + } elseif (!is_readable(Daemon::$config->pidfile->value)) { |
|
207 | 203 | Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be readable.'); |
208 | 204 | Daemon_Bootstrap::$pid = FALSE; |
209 | 205 | $error = true; |
@@ -238,8 +234,7 @@ discard block |
||
238 | 234 | if (($sg = posix_getgrnam(Daemon::$config->group->value)) === FALSE) { |
239 | 235 | Daemon::log('Unexisting group \'' . Daemon::$config->group->value . '\'. You have to replace config-variable \'group\' with existing group-name.'); |
240 | 236 | $error = true; |
241 | - } |
|
242 | - elseif (($sg['gid'] != posix_getgid()) && (posix_getuid() != 0)) { |
|
237 | + } elseif (($sg['gid'] != posix_getgid()) && (posix_getuid() != 0)) { |
|
243 | 238 | Daemon::log('You must have the root privileges to change group.'); |
244 | 239 | $error = true; |
245 | 240 | } |
@@ -252,8 +247,7 @@ discard block |
||
252 | 247 | if (($su = posix_getpwnam(Daemon::$config->user->value)) === FALSE) { |
253 | 248 | Daemon::log('Unexisting user \'' . Daemon::$config->user->value . '\', user not found. You have to replace config-variable \'user\' with existing username.'); |
254 | 249 | $error = true; |
255 | - } |
|
256 | - elseif ( |
|
250 | + } elseif ( |
|
257 | 251 | ($su['uid'] != posix_getuid()) |
258 | 252 | && (posix_getuid() != 0) |
259 | 253 | ) { |
@@ -284,12 +278,10 @@ discard block |
||
284 | 278 | if ($runmode == 'start') { |
285 | 279 | if ($error === FALSE) { |
286 | 280 | Daemon_Bootstrap::start(); |
287 | - } |
|
288 | - else { |
|
281 | + } else { |
|
289 | 282 | exit(6); |
290 | 283 | } |
291 | - } |
|
292 | - elseif ( |
|
284 | + } elseif ( |
|
293 | 285 | $runmode == 'status' |
294 | 286 | || $runmode == 'fullstatus' |
295 | 287 | ) { |
@@ -317,42 +309,36 @@ discard block |
||
317 | 309 | } |
318 | 310 | |
319 | 311 | echo "\n"; |
320 | - } |
|
321 | - elseif ($runmode == 'update') { |
|
312 | + } elseif ($runmode == 'update') { |
|
322 | 313 | if ( |
323 | 314 | (!Daemon_Bootstrap::$pid) |
324 | 315 | || (!posix_kill(Daemon_Bootstrap::$pid, SIGHUP)) |
325 | 316 | ) { |
326 | 317 | echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
327 | 318 | } |
328 | - } |
|
329 | - elseif ($runmode == 'reopenlog') { |
|
319 | + } elseif ($runmode == 'reopenlog') { |
|
330 | 320 | if ( |
331 | 321 | (!Daemon_Bootstrap::$pid) |
332 | 322 | || (!posix_kill(Daemon_Bootstrap::$pid,SIGUSR1)) |
333 | 323 | ) { |
334 | 324 | echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
335 | 325 | } |
336 | - } |
|
337 | - elseif ($runmode == 'reload') { |
|
326 | + } elseif ($runmode == 'reload') { |
|
338 | 327 | if ( |
339 | 328 | (!Daemon_Bootstrap::$pid) |
340 | 329 | || (!posix_kill(Daemon_Bootstrap::$pid,SIGUSR2)) |
341 | 330 | ) { |
342 | 331 | echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Daemon_Bootstrap::$pid ? ' (PID ' . Daemon_Bootstrap::$pid . ')' : '') . ".\n"; |
343 | 332 | } |
344 | - } |
|
345 | - elseif ($runmode == 'restart') { |
|
333 | + } elseif ($runmode == 'restart') { |
|
346 | 334 | if ($error === FALSE) { |
347 | 335 | Daemon_Bootstrap::stop(2); |
348 | 336 | Daemon_Bootstrap::start(); |
349 | 337 | } |
350 | - } |
|
351 | - elseif ($runmode == 'hardrestart') { |
|
338 | + } elseif ($runmode == 'hardrestart') { |
|
352 | 339 | Daemon_Bootstrap::stop(3); |
353 | 340 | Daemon_Bootstrap::start(); |
354 | - } |
|
355 | - elseif ($runmode == 'configtest') { |
|
341 | + } elseif ($runmode == 'configtest') { |
|
356 | 342 | $term = new Terminal; |
357 | 343 | $term->enable_color = true; |
358 | 344 | |
@@ -385,11 +371,9 @@ discard block |
||
385 | 371 | $term->drawtable($rows); |
386 | 372 | |
387 | 373 | echo "\n"; |
388 | - } |
|
389 | - elseif ($runmode == 'stop') { |
|
374 | + } elseif ($runmode == 'stop') { |
|
390 | 375 | Daemon_Bootstrap::stop(); |
391 | - } |
|
392 | - elseif ($runmode == 'hardstop') { |
|
376 | + } elseif ($runmode == 'hardstop') { |
|
393 | 377 | echo '[HARDSTOP] Sending SIGINT to ' . Daemon_Bootstrap::$pid . '... '; |
394 | 378 | |
395 | 379 | $ok = Daemon_Bootstrap::$pid && posix_kill(Daemon_Bootstrap::$pid,SIGINT); |
@@ -440,8 +424,7 @@ discard block |
||
440 | 424 | foreach(self::$params as $name => $desc) { |
441 | 425 | if (empty($desc)) { |
442 | 426 | continue; |
443 | - } |
|
444 | - elseif (!is_array($desc)) { |
|
427 | + } elseif (!is_array($desc)) { |
|
445 | 428 | $term->drawParam($name, $desc); |
446 | 429 | } else { |
447 | 430 | $term->drawParam( |
@@ -518,16 +501,14 @@ discard block |
||
518 | 501 | } |
519 | 502 | |
520 | 503 | $last_arg = $key; |
521 | - } |
|
522 | - elseif (preg_match('~^-([a-zA-Z0-9]+)~', $args[$i], $match)) { |
|
504 | + } elseif (preg_match('~^-([a-zA-Z0-9]+)~', $args[$i], $match)) { |
|
523 | 505 | for ($j = 0, $jl = strlen($match[1]); $j < $jl; ++$j) { |
524 | 506 | $key = $match[1]{$j}; |
525 | 507 | $out[$key] = true; |
526 | 508 | } |
527 | 509 | |
528 | 510 | $last_arg = $key; |
529 | - } |
|
530 | - elseif ($last_arg !== NULL) { |
|
511 | + } elseif ($last_arg !== NULL) { |
|
531 | 512 | $out[$last_arg] = $args[$i]; |
532 | 513 | } |
533 | 514 | } |
@@ -102,6 +102,9 @@ |
||
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | + /** |
|
106 | + * @param string $path |
|
107 | + */ |
|
105 | 108 | public function loadFile($path) { |
106 | 109 | $parser = new Daemon_ConfigParser($path,$this); |
107 | 110 | $this->onLoad(); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public $configfile = '/etc/phpdaemon/phpd.conf;/etc/phpd/phpd.conf;./conf/phpd.conf'; |
21 | 21 | public $path = '/etc/phpdaemon/AppResolver.php;./conf/AppResolver.php'; |
22 | 22 | public $appfilepath = '{app-*,applications}/%s.php'; |
23 | - public $autoload = NULL; |
|
23 | + public $autoload = NULL; |
|
24 | 24 | |
25 | 25 | // Master-related |
26 | 26 | public $mpmdelay = '0.1s'; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | static $sizes = array('maxmemoryusage'); |
77 | 77 | static $times = array('maxidle', 'autoreload', 'mpmdelay', 'eiosetmaxpolltime'); |
78 | 78 | static $numbers = array( |
79 | - 'maxrequests', 'autogc','minworkers','maxworkers','minspareworkers','maxspareworkers','masterpriority', 'ipcthreadpriority', |
|
79 | + 'maxrequests', 'autogc', 'minworkers', 'maxworkers', 'minspareworkers', 'maxspareworkers', 'masterpriority', 'ipcthreadpriority', |
|
80 | 80 | 'eiosetmaxidle', 'eiosetmaxparallel', 'eiosetmaxpollreqs', 'eiosetminparallel', 'verbose', 'verbosetty' |
81 | 81 | ); |
82 | 82 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | public function loadFile($path) { |
106 | - $parser = new Daemon_ConfigParser($path,$this); |
|
106 | + $parser = new Daemon_ConfigParser($path, $this); |
|
107 | 107 | $this->onLoad(); |
108 | 108 | return !$parser->errorneus; |
109 | 109 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | return isset($this->{$offset}) ? $this->{$offset}->value : NULL; |
144 | 144 | } |
145 | 145 | |
146 | - public function offsetSet($offset,$value) { |
|
146 | + public function offsetSet($offset, $value) { |
|
147 | 147 | $offset = $this->getRealOffsetName($offset); |
148 | 148 | |
149 | 149 | $this->{$offset} = $value; |
@@ -83,14 +83,11 @@ discard block |
||
83 | 83 | foreach ($this as $name => $value) { |
84 | 84 | if (in_array($name, $sizes)) { |
85 | 85 | $entry = new Daemon_ConfigEntrySize; |
86 | - } |
|
87 | - elseif (in_array($name, $times)) { |
|
86 | + } elseif (in_array($name, $times)) { |
|
88 | 87 | $entry = new Daemon_ConfigEntryTime; |
89 | - } |
|
90 | - elseif (in_array($name, $numbers)) { |
|
88 | + } elseif (in_array($name, $numbers)) { |
|
91 | 89 | $entry = new Daemon_ConfigEntryNumber; |
92 | - } |
|
93 | - elseif ($name === 'configfile') { |
|
90 | + } elseif ($name === 'configfile') { |
|
94 | 91 | $entry = new Daemon_ConfigEntryConfigFile; |
95 | 92 | } else { |
96 | 93 | $entry = new Daemon_ConfigEntry; |
@@ -184,8 +181,7 @@ discard block |
||
184 | 181 | Daemon::$config->{$k}->setHumanValue($v); |
185 | 182 | Daemon::$config->{$k}->source = 'cmdline'; |
186 | 183 | |
187 | - } |
|
188 | - else { |
|
184 | + } else { |
|
189 | 185 | Daemon::log('Unrecognized parameter \'' . $k . '\''); |
190 | 186 | $error = TRUE; |
191 | 187 | } |
@@ -24,6 +24,9 @@ |
||
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | + /** |
|
28 | + * @param boolean $value |
|
29 | + */ |
|
27 | 30 | public function setValue($value) { |
28 | 31 | $old = $this->value; |
29 | 32 | $this->value = $value; |
@@ -27,6 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Constructor |
30 | + * @param Daemon_Config $config |
|
30 | 31 | * @return void |
31 | 32 | */ |
32 | 33 | public function __construct($file, $config, $included = FALSE) |
@@ -306,6 +307,9 @@ discard block |
||
306 | 307 | * Raises error message. |
307 | 308 | * @param string Message. |
308 | 309 | * @param string Level. |
310 | + * @param string $msg |
|
311 | + * @param integer $line |
|
312 | + * @param integer $col |
|
309 | 313 | * @return void |
310 | 314 | */ |
311 | 315 | public function raiseError($msg, $level = 'emerg', $line = null, $col = null) { |
@@ -324,6 +328,7 @@ discard block |
||
324 | 328 | |
325 | 329 | /** |
326 | 330 | * Executes token-parse callback. |
331 | + * @param string $c |
|
327 | 332 | * @return void |
328 | 333 | */ |
329 | 334 | public function token($token, $c) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $cfg->revision = ++Daemon_Config::$lastRevision; |
38 | 38 | $cfg->data = file_get_contents($file); |
39 | 39 | |
40 | - if (substr($cfg->data,0,2) === '#!') { |
|
40 | + if (substr($cfg->data, 0, 2) === '#!') { |
|
41 | 41 | if (!is_executable($file)) { |
42 | 42 | $this->raiseError('Shebang (#!) detected in the first line, but file hasn\'t +x mode.'); |
43 | 43 | return; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $str = ''; |
59 | 59 | ++$cfg->p; |
60 | 60 | |
61 | - for (;$cfg->p < $cfg->len;++$cfg->p) { |
|
61 | + for (;$cfg->p < $cfg->len; ++$cfg->p) { |
|
62 | 62 | $c = $cfg->getCurrentChar(); |
63 | 63 | |
64 | 64 | if ($c === $q) { |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if ($c === "\n") { |
112 | 112 | $newLineDetected = $prePoint; |
113 | 113 | } |
114 | - if ($elTypes[$i] !== NULL) { |
|
114 | + if ($elTypes[$i] !== NULL) { |
|
115 | 115 | ++$i; |
116 | 116 | $elTypes[$i] = NULL; |
117 | 117 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | ($c === '"') |
121 | 121 | || ($c === '\'') |
122 | 122 | ) { |
123 | - if ($elTypes[$i] != NULL) { |
|
123 | + if ($elTypes[$i] != NULL) { |
|
124 | 124 | $cfg->raiseError('Unexpected T_STRING.'); |
125 | 125 | } |
126 | 126 | |
127 | 127 | $string = call_user_func($cfg->tokens[Daemon_ConfigParser::T_STRING], $cfg, $c); |
128 | 128 | --$cfg->p; |
129 | 129 | |
130 | - if ($elTypes[$i] === NULL) { |
|
130 | + if ($elTypes[$i] === NULL) { |
|
131 | 131 | $elements[$i] = $string; |
132 | 132 | $elTypes[$i] = Daemon_ConfigParser::T_STRING; |
133 | 133 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $tokenType = Daemon_ConfigParser::T_BLOCK; |
147 | 147 | break; |
148 | 148 | } else { |
149 | - if ($elTypes[$i] === Daemon_ConfigParser::T_STRING) { |
|
149 | + if ($elTypes[$i] === Daemon_ConfigParser::T_STRING) { |
|
150 | 150 | $cfg->raiseError('Unexpected T_CVALUE.'); |
151 | 151 | } else { |
152 | 152 | if (!isset($elements[$i])) { |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | |
191 | 191 | if ($name === 'include') { |
192 | 192 | $path = $elements[1]; |
193 | - if (substr($path,0,1) !== '/') { |
|
194 | - $path = 'conf/'.$path; |
|
193 | + if (substr($path, 0, 1) !== '/') { |
|
194 | + $path = 'conf/' . $path; |
|
195 | 195 | } |
196 | 196 | $files = glob($path); |
197 | 197 | if ($files) { |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | $parser = new Daemon_ConfigParser($fn, $scope, true); |
200 | 200 | } |
201 | 201 | } |
202 | - } elseif (substr(strtolower($elements[0]),0,4) === 'mod-') { // @TODO: remove in 1.0 |
|
202 | + } elseif (substr(strtolower($elements[0]), 0, 4) === 'mod-') { // @TODO: remove in 1.0 |
|
203 | 203 | $cfg->raiseError('Variable started with \'mod-\'. This style is deprecated. You should replace it with block.'); |
204 | 204 | } else { |
205 | 205 | if (sizeof($elements) > 2) { |
206 | 206 | $cfg->raiseError('Too many arguments.'); |
207 | 207 | } |
208 | 208 | if (isset($scope->{$name})) { |
209 | - if ($scope->{$name}->source !== 'cmdline') { |
|
209 | + if ($scope->{$name}->source !== 'cmdline') { |
|
210 | 210 | if (!isset($elements[1])) { |
211 | 211 | $elements[1] = true; |
212 | 212 | $elTypes[1] = Daemon_ConfigParser::T_CVALUE; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $scope->{$name}->setValue($elements[1]); |
234 | 234 | $scope->{$name}->setValueType($elTypes[1]); |
235 | 235 | } |
236 | - else {$cfg->raiseError('Unrecognized parameter \''.$name.'\'');} |
|
236 | + else {$cfg->raiseError('Unrecognized parameter \'' . $name . '\''); } |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | elseif ($tokenType === Daemon_ConfigParser::T_BLOCK) { |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | ); |
252 | 252 | } |
253 | 253 | } else { |
254 | - $cfg->raiseError('Unexpected char \''.Debug::exportBytes($c).'\''); |
|
254 | + $cfg->raiseError('Unexpected char \'' . Debug::exportBytes($c) . '\''); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | ); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $e = end($this->state); |
262 | 262 | $cfg->token($e[0], $c); |
263 | 263 | } |
264 | - if (!$included) {$this->purgeScope($this->result);} |
|
264 | + if (!$included) {$this->purgeScope($this->result); } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $cfg = $this; |
273 | 273 | foreach ($scope as $name => $obj) { |
274 | 274 | if ($obj instanceof Daemon_ConfigEntry) { |
275 | - if ($obj->source === 'config' && ($obj->revision < $cfg->revision)) { |
|
275 | + if ($obj->source === 'config' && ($obj->revision < $cfg->revision)) { |
|
276 | 276 | if (!$obj->resetToDefault()) { |
277 | 277 | unset($scope->{$name}); |
278 | 278 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | elseif ($obj instanceof Daemon_ConfigSection) { |
282 | 282 | |
283 | - if ($obj->source === 'config' && ($obj->revision < $cfg->revision)) { |
|
283 | + if ($obj->source === 'config' && ($obj->revision < $cfg->revision)) { |
|
284 | 284 | if (sizeof($obj) === 0) { |
285 | 285 | unset($scope->{$name}); |
286 | 286 | } |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | $line = $this->line; |
317 | 317 | } |
318 | 318 | if ($col === null) { |
319 | - $col = $this->col -1 ; |
|
319 | + $col = $this->col - 1; |
|
320 | 320 | } |
321 | 321 | |
322 | - Daemon::log('[conf#' . $level . '][' . $this->file . ' L:' . $line . ' C: ' . $col . '] '.$msg); |
|
322 | + Daemon::log('[conf#' . $level . '][' . $this->file . ' L:' . $line . ' C: ' . $col . '] ' . $msg); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | if ($c === $q) { |
65 | 65 | ++$cfg->p; |
66 | 66 | break; |
67 | - } |
|
68 | - elseif ($c === '\\') { |
|
67 | + } elseif ($c === '\\') { |
|
69 | 68 | if ($cfg->getNextChar() === $q) { |
70 | 69 | $str .= $q; |
71 | 70 | ++$cfg->p; |
@@ -84,19 +83,16 @@ discard block |
||
84 | 83 | return $str; |
85 | 84 | }, |
86 | 85 | self::T_ALL => function($cfg, $c) { |
87 | - if (ctype_space($c)) { } |
|
88 | - elseif ($c === '#') { |
|
86 | + if (ctype_space($c)) { } elseif ($c === '#') { |
|
89 | 87 | $cfg->state[] = array(Daemon_ConfigParser::T_COMMENT); |
90 | - } |
|
91 | - elseif ($c === '}') { |
|
88 | + } elseif ($c === '}') { |
|
92 | 89 | if (sizeof($cfg->state) > 1) { |
93 | 90 | $cfg->purgeScope($cfg->getCurrentScope()); |
94 | 91 | array_pop($cfg->state); |
95 | 92 | } else { |
96 | 93 | $cfg->raiseError('Unexpected \'}\''); |
97 | 94 | } |
98 | - } |
|
99 | - elseif (ctype_alnum($c)) { |
|
95 | + } elseif (ctype_alnum($c)) { |
|
100 | 96 | $elements = array(''); |
101 | 97 | $elTypes = array(NULL); |
102 | 98 | $i = 0; |
@@ -115,8 +111,7 @@ discard block |
||
115 | 111 | ++$i; |
116 | 112 | $elTypes[$i] = NULL; |
117 | 113 | } |
118 | - } |
|
119 | - elseif ( |
|
114 | + } elseif ( |
|
120 | 115 | ($c === '"') |
121 | 116 | || ($c === '\'') |
122 | 117 | ) { |
@@ -131,18 +126,15 @@ discard block |
||
131 | 126 | $elements[$i] = $string; |
132 | 127 | $elTypes[$i] = Daemon_ConfigParser::T_STRING; |
133 | 128 | } |
134 | - } |
|
135 | - elseif ($c === '}') { |
|
129 | + } elseif ($c === '}') { |
|
136 | 130 | $cfg->raiseError('Unexpected \'}\' instead of \';\' or \'{\''); |
137 | - } |
|
138 | - elseif ($c === ';') { |
|
131 | + } elseif ($c === ';') { |
|
139 | 132 | if ($newLineDetected) { |
140 | 133 | $this->raiseError('Unexpected new-line instead of \';\'', 'notice', $newLineDetected[0], $newLineDetected[1]); |
141 | 134 | } |
142 | 135 | $tokenType = Daemon_ConfigParser::T_VAR; |
143 | 136 | break; |
144 | - } |
|
145 | - elseif ($c === '{') { |
|
137 | + } elseif ($c === '{') { |
|
146 | 138 | $tokenType = Daemon_ConfigParser::T_BLOCK; |
147 | 139 | break; |
148 | 140 | } else { |
@@ -163,19 +155,16 @@ discard block |
||
163 | 155 | if (Daemon_ConfigParser::T_CVALUE === $v) { |
164 | 156 | if (ctype_digit($elements[$k])) { |
165 | 157 | $elements[$k] = (int) $elements[$k]; |
166 | - } |
|
167 | - elseif (is_numeric($elements[$k])) { |
|
158 | + } elseif (is_numeric($elements[$k])) { |
|
168 | 159 | $elements[$k] = (float) $elements[$k]; |
169 | 160 | } else { |
170 | 161 | $l = strtolower($elements[$k]); |
171 | 162 | |
172 | 163 | if (($l === 'true') || ($l === 'on')) { |
173 | 164 | $elements[$k] = true; |
174 | - } |
|
175 | - elseif (($l === 'false') || ($l === 'off')) { |
|
165 | + } elseif (($l === 'false') || ($l === 'off')) { |
|
176 | 166 | $elements[$k] = false; |
177 | - } |
|
178 | - elseif ($l === 'null') { |
|
167 | + } elseif ($l === 'null') { |
|
179 | 168 | $elements[$k] = null; |
180 | 169 | } |
181 | 170 | } |
@@ -183,8 +172,7 @@ discard block |
||
183 | 172 | } |
184 | 173 | if ($tokenType === 0) { |
185 | 174 | $cfg->raiseError('Expected \';\' or \'{\''); |
186 | - } |
|
187 | - elseif ($tokenType === Daemon_ConfigParser::T_VAR) { |
|
175 | + } elseif ($tokenType === Daemon_ConfigParser::T_VAR) { |
|
188 | 176 | $name = str_replace('-', '', strtolower($elements[0])); |
189 | 177 | $scope = $cfg->getCurrentScope(); |
190 | 178 | |
@@ -232,11 +220,9 @@ discard block |
||
232 | 220 | } |
233 | 221 | $scope->{$name}->setValue($elements[1]); |
234 | 222 | $scope->{$name}->setValueType($elTypes[1]); |
235 | - } |
|
236 | - else {$cfg->raiseError('Unrecognized parameter \''.$name.'\'');} |
|
223 | + } else {$cfg->raiseError('Unrecognized parameter \''.$name.'\'');} |
|
237 | 224 | } |
238 | - } |
|
239 | - elseif ($tokenType === Daemon_ConfigParser::T_BLOCK) { |
|
225 | + } elseif ($tokenType === Daemon_ConfigParser::T_BLOCK) { |
|
240 | 226 | $scope = $cfg->getCurrentScope(); |
241 | 227 | $sectionName = implode('-', $elements); |
242 | 228 | $sectionName = strtr($sectionName, '-. ', ':::'); |
@@ -277,14 +263,12 @@ discard block |
||
277 | 263 | unset($scope->{$name}); |
278 | 264 | } |
279 | 265 | } |
280 | - } |
|
281 | - elseif ($obj instanceof Daemon_ConfigSection) { |
|
266 | + } elseif ($obj instanceof Daemon_ConfigSection) { |
|
282 | 267 | |
283 | 268 | if ($obj->source === 'config' && ($obj->revision < $cfg->revision)) { |
284 | 269 | if (sizeof($obj) === 0) { |
285 | 270 | unset($scope->{$name}); |
286 | - } |
|
287 | - elseif (isset($obj->enable)) { |
|
271 | + } elseif (isset($obj->enable)) { |
|
288 | 272 | $obj->enable->setValue(FALSE); |
289 | 273 | } |
290 | 274 | } |
@@ -132,6 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * Log something |
134 | 134 | * @param string - Message. |
135 | + * @param string $message |
|
135 | 136 | * @return void |
136 | 137 | */ |
137 | 138 | public function log($message) { |
@@ -162,7 +163,7 @@ discard block |
||
162 | 163 | /** |
163 | 164 | * @todo description? |
164 | 165 | * @param boolean - Hard? If hard, we shouldn't wait for graceful shutdown of the running applications. |
165 | - * @return boolean - Ready? |
|
166 | + * @return boolean|null - Ready? |
|
166 | 167 | */ |
167 | 168 | public function shutdown($hard = FALSE) { |
168 | 169 | $error = error_get_last(); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function prepareSystemEnv() { |
69 | 69 | proc_nice(Daemon::$config->ipcthreadpriority->value); |
70 | - register_shutdown_function(array($this,'shutdown')); |
|
70 | + register_shutdown_function(array($this, 'shutdown')); |
|
71 | 71 | |
72 | 72 | $this->setproctitle( |
73 | 73 | Daemon::$runName . ': IPC process' |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $error = error_get_last(); |
169 | 169 | if ($error) { |
170 | 170 | if ($error['type'] === E_ERROR) { |
171 | - $this->log('crashed by error \''.$error['message'].'\' at '.$error['file'].':'.$error['line']); |
|
171 | + $this->log('crashed by error \'' . $error['message'] . '\' at ' . $error['file'] . ':' . $error['line']); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | } |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | if (posix_getuid() != 0) { |
88 | 88 | $this->log('You must have the root privileges to change root.'); |
89 | 89 | exit(0); |
90 | - } |
|
91 | - elseif (!chroot(Daemon::$config->chroot->value)) { |
|
90 | + } elseif (!chroot(Daemon::$config->chroot->value)) { |
|
92 | 91 | Daemon::log('Couldn\'t change root to \'' . Daemon::$config->chroot->value . '\'.'); |
93 | 92 | exit(0); |
94 | 93 | } |
@@ -98,8 +97,7 @@ discard block |
||
98 | 97 | if ($sg === FALSE) { |
99 | 98 | $this->log('Couldn\'t change group to \'' . Daemon::$config->group->value . '\'. You must replace config-variable \'group\' with existing group.'); |
100 | 99 | exit(0); |
101 | - } |
|
102 | - elseif ( |
|
100 | + } elseif ( |
|
103 | 101 | ($sg['gid'] != posix_getgid()) |
104 | 102 | && (!posix_setgid($sg['gid'])) |
105 | 103 | ) { |
@@ -112,8 +110,7 @@ discard block |
||
112 | 110 | if ($su === FALSE) { |
113 | 111 | $this->log('Couldn\'t change user to \'' . Daemon::$config->user->value . '\', user not found. You must replace config-variable \'user\' with existing username.'); |
114 | 112 | exit(0); |
115 | - } |
|
116 | - elseif ( |
|
113 | + } elseif ( |
|
117 | 114 | ($su['uid'] != posix_getuid()) |
118 | 115 | && (!posix_setuid($su['uid'])) |
119 | 116 | ) { |
@@ -139,6 +139,7 @@ discard block |
||
139 | 139 | /** |
140 | 140 | * Log something |
141 | 141 | * @param string - Message. |
142 | + * @param string $message |
|
142 | 143 | * @return void |
143 | 144 | */ |
144 | 145 | public function log($message) { |
@@ -167,6 +168,7 @@ discard block |
||
167 | 168 | } |
168 | 169 | /** |
169 | 170 | * @todo description missed |
171 | + * @param integer $id |
|
170 | 172 | */ |
171 | 173 | public function reloadWorker($id) { |
172 | 174 | if (isset($this->workers->threads[$id])) { |
@@ -322,6 +324,9 @@ discard block |
||
322 | 324 | $this->shutdown(SIGINT); |
323 | 325 | } |
324 | 326 | |
327 | + /** |
|
328 | + * @param integer $signo |
|
329 | + */ |
|
325 | 330 | public function signalToChildren($signo) { |
326 | 331 | foreach ($this->collections as $col) { |
327 | 332 | $col->signal($signo); |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | posix_setsid(); |
156 | 156 | proc_nice(Daemon::$config->masterpriority->value); |
157 | 157 | if (!Daemon::$config->verbosetty->value) { |
158 | - fclose(STDIN); |
|
159 | - fclose(STDOUT); |
|
160 | - fclose(STDERR); |
|
161 | - } |
|
158 | + fclose(STDIN); |
|
159 | + fclose(STDOUT); |
|
160 | + fclose(STDERR); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | $this->setproctitle( |
164 | 164 | Daemon::$runName . ': master process' |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Spawn IPC process |
|
216 | - * @param $n - integer - number of workers to spawn |
|
217 | - * @return boolean - success |
|
218 | - */ |
|
215 | + * Spawn IPC process |
|
216 | + * @param $n - integer - number of workers to spawn |
|
217 | + * @return boolean - success |
|
218 | + */ |
|
219 | 219 | public function spawnIPCThread() { |
220 | 220 | if (FS::$supported) { |
221 | 221 | eio_event_loop(); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @return void |
152 | 152 | */ |
153 | 153 | public function prepareSystemEnv() { |
154 | - register_shutdown_function(array($this,'onShutdown')); |
|
154 | + register_shutdown_function(array($this, 'onShutdown')); |
|
155 | 155 | posix_setsid(); |
156 | 156 | proc_nice(Daemon::$config->masterpriority->value); |
157 | 157 | if (!Daemon::$config->verbosetty->value) { |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $this->shutdown = true; |
292 | 292 | $this->waitAll(true); |
293 | 293 | Daemon::$shm_wstate->delete(); |
294 | - file_put_contents(Daemon::$config->pidfile->value,''); |
|
294 | + file_put_contents(Daemon::$config->pidfile->value, ''); |
|
295 | 295 | exit(0); |
296 | 296 | } |
297 | 297 |