diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e2c037ac0..57fccd1b2 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1561,6 +1561,8 @@ class Server{ $this->logger->warning($this->getName() . " may not work right with less than 128MB of memory"); } @ini_set("memory_limit", $memory); + $this->logger->notice("The memory limit will only affect the main thread, and it's unreliable."); + $this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded"); } if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){ @@ -1855,6 +1857,8 @@ class Server{ $this->logger->warning($this->getName() . " may not work right with less than 256MB of memory", true, true, 0); } @ini_set("memory_limit", $memory); + $this->logger->notice("The memory limit will only affect the main thread, and it's unreliable."); + $this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded"); } if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){ @@ -2192,14 +2196,8 @@ class Server{ return; } - $usage = $this->getMemoryUsage(); - if($usage === null){ - $usage = round((memory_get_usage() / 1024) / 1024, 2) . - "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . - " MB @ " . $this->getThreadCount() . " threads"; - }else{ - $usage = round(($usage / 1024) / 1024, 2) . " MB @ " . $this->getThreadCount() . " threads"; - } + $u = $this->getMemoryUsage(true); + $usage = round(($u[0] / 1024) / 1024, 2) . "/".round(($u[1] / 1024) / 1024, 2)." MB @ " . $this->getThreadCount() . " threads"; echo "\x1b]0;" . $this->getName() . " " . $this->getPocketMineVersion() . @@ -2213,34 +2211,31 @@ class Server{ public function getMemoryUsage($advanced = false){ $VmSize = null; - $VmHWM = null; + $VmRSS = null; if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){ $status = file_get_contents("/proc/self/status"); - if(preg_match("/VmHWM:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ - $VmHWM = $matches[1] * 1024; + if(preg_match("/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ + $VmRSS = $matches[1] * 1024; } - if(preg_match("/VmData:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ - $VmData = $matches[1] * 1024; + if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0){ + $VmSize = $matches[1] * 1024; } } - if($VmHWM === null){ - $VmHWM = memory_get_usage(); + if($VmRSS === null){ + $VmRSS = memory_get_usage(); } if(!$advanced){ - return $VmHWM; + return $VmRSS; } if($VmSize === null){ $VmSize = memory_get_usage(true); } - return [ - "hardware" => $VmHWM, - "virtual" => $VmSize, - ]; + return [$VmRSS, $VmSize]; } public function getThreadCount(){ diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index d0528c04d..5c129df4d 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -25,10 +25,6 @@ namespace pocketmine\utils; use pocketmine\entity\Entity; -/** - * WARNING: This class is available on the PocketMine-MP Zephir project. - * If this class is modified, remember to modify the PHP C extension. - */ class Binary{ const BIG_ENDIAN = 0x00; const LITTLE_ENDIAN = 0x01; diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 8b44ab432..10c505241 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -47,7 +47,7 @@ class MainLogger extends \AttachableThreadedLogger{ $this->logFile = $logFile; $this->logDebug = (bool) $logDebug; $this->logStream = ""; - $this->start(PTHREADS_INHERIT_NONE); + $this->start(); } /** @@ -190,7 +190,11 @@ class MainLogger extends \AttachableThreadedLogger{ $this->attachment->call($level, $message); } - $this->logStream .= date("Y-m-d", $now) . " " . $cleanMessage; + $str = date("Y-m-d", $now) . " " . $cleanMessage . "\n"; + $this->synchronized(function($str){ + $this->logStream .= $str; + $this->notify(); + }, $str); } public function run(){ @@ -201,15 +205,15 @@ class MainLogger extends \AttachableThreadedLogger{ } while($this->shutdown === false){ - if(strlen($this->logStream) > 0){ - $this->lock(); - $chunk = $this->logStream; - $this->logStream = ""; - $this->unlock(); - fwrite($this->logResource, $chunk); - }else{ - usleep(250000); - } + $this->synchronized(function(){ + if(strlen($this->logStream) > 0){ + $chunk = $this->logStream; + $this->logStream = ""; + fwrite($this->logResource, $chunk); + }else{ + $this->wait(250000); + } + }); } if(strlen($this->logStream) > 0){ diff --git a/src/pocketmine/utils/Random.php b/src/pocketmine/utils/Random.php index fe2b0cf8c..c62e8b3e4 100644 --- a/src/pocketmine/utils/Random.php +++ b/src/pocketmine/utils/Random.php @@ -24,8 +24,6 @@ namespace pocketmine\utils; /** * Unsecure Random Number Noise, used for fast seeded values - * WARNING: This class is available on the PocketMine-MP Zephir project. - * If this class is modified, remember to modify the PHP C extension. */ class Random{ diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index 014ca9d68..00c3d9520 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -70,9 +70,9 @@ abstract class TextFormat{ */ public static function clean($string, $removeFormat = true){ if($removeFormat){ - return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b\\[[0-9;]+m/"], "", $string); + return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string); } - return preg_replace("/\x1b\\[[0-9;]+m/", "", $string); + return preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string); } /** diff --git a/src/raklib b/src/raklib index 7c0888f4a..639108fb3 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 7c0888f4ad51c4eb9b695c38691b16aa08522493 +Subproject commit 639108fb3aeb48a113df3b31516af6ac4f5ba402 diff --git a/src/spl b/src/spl index 695451daf..5ad5b3535 160000 --- a/src/spl +++ b/src/spl @@ -1 +1 @@ -Subproject commit 695451daf403d86e9db11e6119a6c9cef7f85463 +Subproject commit 5ad5b3535c9519b2e013a61a2d55fccae014e037