diff --git a/src/utils/ServerKiller.php b/src/utils/ServerKiller.php index 98129f48f..514a265ba 100644 --- a/src/utils/ServerKiller.php +++ b/src/utils/ServerKiller.php @@ -24,7 +24,8 @@ declare(strict_types=1); namespace pocketmine\utils; use pocketmine\thread\Thread; -use function time; +use function hrtime; +use function intdiv; class ServerKiller extends Thread{ private bool $stopped = false; @@ -34,13 +35,15 @@ class ServerKiller extends Thread{ ){} protected function onRun() : void{ - $start = time(); - $this->synchronized(function() : void{ - if(!$this->stopped){ - $this->wait($this->time * 1000000); + $start = hrtime(true); + $remaining = $this->time * 1_000_000; + $this->synchronized(function() use (&$remaining, $start) : void{ + while(!$this->stopped && $remaining > 0){ + $this->wait($remaining); + $remaining -= intdiv(hrtime(true) - $start, 1000); } }); - if(time() - $start >= $this->time){ + if($remaining <= 0){ echo "\nTook too long to stop, server was killed forcefully!\n"; @Process::kill(Process::pid()); }