Browse Source

fix: avoid `pcntl_wait` blocking

master
dnomd343 2 years ago
parent
commit
6f0db006ce
  1. 5
      main.php
  2. 4
      src/Daemon.php
  3. 2
      src/Logger.php

5
main.php

@ -25,8 +25,11 @@ $vlmcsd = array(
);
logging::info('Loading kms-server (' . $version . ')');
declare(ticks = 1);
pcntl_signal(SIGCHLD, 'subExit'); // receive SIGCHLD signal
pcntl_signal(SIGCHLD, function() { // receive SIGCHLD signal
pcntl_wait($status, WNOHANG); // avoid zombie process
});
new Process($nginx['command']);
logging::info('Start nginx server...OK');

4
src/Daemon.php

@ -3,10 +3,6 @@
require_once 'Logger.php';
require_once 'Process.php';
function subExit(): void {
pcntl_wait($status); // avoid zombie process
}
function msSleep(int $ms): void { // sleep for xxx ms
for ($i = 0; $i < $ms; $i++) {
usleep(1000); // split multiple times (avoid SIGCHLD signal)

2
src/Logger.php

@ -1,6 +1,6 @@
<?php
logging::$logLevel = logging::INFO;
logging::$logLevel = logging::DEBUG;
$logColor = array(
logging::DEBUG => '37m', // white

Loading…
Cancel
Save