diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 0bfdb26e6..5b7e58170 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -168,16 +168,6 @@ namespace pocketmine { error_reporting(-1); - function error_handler($severity, $message, $file, $line){ - if(error_reporting() & $severity){ - throw new \ErrorException($message, 0, $severity, $file, $line); - }else{ //stfu operator - return true; - } - } - - set_error_handler('\pocketmine\error_handler'); - if(\Phar::running(true) !== ""){ define('pocketmine\PATH', \Phar::running(true) . "/"); }else{ @@ -198,6 +188,8 @@ namespace pocketmine { composer_error_die("Composer autoloader not found."); } + set_error_handler([Utils::class, 'errorExceptionHandler']); + /* * We now use the Composer autoloader, but this autoloader is still for loading plugins. */ diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index 8407fdcb0..a2475bee6 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -26,6 +26,7 @@ namespace pocketmine\scheduler; use pocketmine\Server; class AsyncPool{ + private const WORKER_START_OPTIONS = PTHREADS_INHERIT_INI | PTHREADS_INHERIT_CONSTANTS; /** @var Server */ private $server; @@ -62,7 +63,7 @@ class AsyncPool{ $this->workerUsage[$i] = 0; $this->workers[$i] = new AsyncWorker($this->logger, $i + 1, $this->workerMemoryLimit); $this->workers[$i]->setClassLoader($this->classLoader); - $this->workers[$i]->start(); + $this->workers[$i]->start(self::WORKER_START_OPTIONS); } } @@ -76,7 +77,7 @@ class AsyncPool{ $this->workerUsage[$i] = 0; $this->workers[$i] = new AsyncWorker($this->logger, $i + 1, $this->workerMemoryLimit); $this->workers[$i]->setClassLoader($this->classLoader); - $this->workers[$i]->start(); + $this->workers[$i]->start(self::WORKER_START_OPTIONS); } $this->size = $newSize; } diff --git a/src/pocketmine/scheduler/AsyncWorker.php b/src/pocketmine/scheduler/AsyncWorker.php index 3baa046c7..221d4aa5d 100644 --- a/src/pocketmine/scheduler/AsyncWorker.php +++ b/src/pocketmine/scheduler/AsyncWorker.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine\scheduler; +use pocketmine\utils\MainLogger; +use pocketmine\utils\Utils; use pocketmine\Worker; class AsyncWorker extends Worker{ @@ -43,9 +45,16 @@ class AsyncWorker extends Worker{ public function run(){ error_reporting(-1); - set_error_handler('\pocketmine\error_handler'); $this->registerClassLoader(); + + //set this after the autoloader is registered + set_error_handler([Utils::class, 'errorExceptionHandler']); + + if($this->logger instanceof MainLogger){ + $this->logger->registerStatic(); + } + gc_enable(); if($this->memoryLimit > 0){ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index d15a59cd7..82b9aed6c 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -634,4 +634,21 @@ class Utils{ return array_combine($matches[1], array_map("trim", $matches[2])); } + + /** + * @param int $severity + * @param string $message + * @param string $file + * @param int $line + * + * @return bool + * @throws \ErrorException + */ + public static function errorExceptionHandler(int $severity, string $message, string $file, int $line) : bool{ + if(error_reporting() & $severity){ + throw new \ErrorException($message, 0, $severity, $file, $line); + } + + return true; //stfu operator + } }