pocketmine\utils\Utils::getCoreCount PHP Method

getCoreCount() public static method

public static getCoreCount ( $recalculate = false )
    public static function getCoreCount($recalculate = false)
    {
        static $processors = 0;
        if ($processors > 0 and !$recalculate) {
            return $processors;
        } else {
            $processors = 0;
        }
        switch (Utils::getOS()) {
            case "linux":
            case "android":
                if (file_exists("/proc/cpuinfo")) {
                    foreach (file("/proc/cpuinfo") as $l) {
                        if (preg_match('/^processor[ \\t]*:[ \\t]*[0-9]+$/m', $l) > 0) {
                            ++$processors;
                        }
                    }
                } else {
                    if (preg_match("/^([0-9]+)\\-([0-9]+)\$/", trim(@file_get_contents("/sys/devices/system/cpu/present")), $matches) > 0) {
                        $processors = (int) ($matches[2] - $matches[1]);
                    }
                }
                break;
            case "bsd":
            case "mac":
                $processors = (int) `sysctl -n hw.ncpu`;
                $processors = (int) `sysctl -n hw.ncpu`;
                break;
            case "win":
                $processors = (int) getenv("NUMBER_OF_PROCESSORS");
                break;
        }
        return $processors;
    }

Usage Example

Example #1
0
 public function write()
 {
     $spawningPool = new SpawningPool($this->getServer(), Utils::getCoreCount());
     $this->setPrivateVariableData($this->getServer()->getScheduler(), "asyncPool", $spawningPool);
     foreach ($this->getServer()->getLevels() as $level) {
         $level->registerGenerator();
     }
 }
All Usage Examples Of pocketmine\utils\Utils::getCoreCount