diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 56f7fc9f..112dfb64 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -277,6 +277,9 @@ class ConsoleAPI{ public static function info($msg){ console("[INFO] ".$msg); } + public static function notice($msg){ + console("[NOTICE] ".$msg); + } public static function warn($msg){ console("[WARNING] ".$msg); } @@ -309,6 +312,7 @@ class ConsoleLoop extends Thread{ while(!$this->stop){ $this->line = $this->readLine(); + if($this->stop) break; $this->synchronized(function($t) { $this->wait(); $this->line = false; @@ -324,6 +328,14 @@ class ConsoleLoop extends Thread{ private function readLine(){ if($this->fp){ + do{ + if($this->stop){ + ConsoleAPI::notice("Force stopping console thread!"); + return ""; + } + $read = [$this->fp]; + $changed = stream_select($read, $write, $except, 1); + }while($changed <= 0); $line = trim(fgets($this->fp)); }else{ $line = trim(readline("")); diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index c0c68df1..f50e4f2e 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -50,6 +50,10 @@ class PluginAPI extends stdClass{ } public function __destruct(){ + if(!isset($this->plugins) || !is_array($this->plugins)){ + ConsoleAPI::warn("PluginAPI::\$plugins is null (destructor called twice?)"); + return; + } foreach($this->plugins as $p){ if(method_exists($p[0], "__destruct")){$p[0]->__destruct();}; } @@ -308,4 +312,4 @@ class RequiredPluginEntry{ //Use this as object of requirements array } } - \ No newline at end of file +