当前位置: 首页>>代码示例>>PHP>>正文


PHP event\TimingsHandler类代码示例

本文整理汇总了PHP中pocketmine\event\TimingsHandler的典型用法代码示例。如果您正苦于以下问题:PHP TimingsHandler类的具体用法?PHP TimingsHandler怎么用?PHP TimingsHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TimingsHandler类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stopTiming

 public function stopTiming()
 {
     if (PluginManager::$useTimings) {
         if (--$this->timingDepth !== 0 or $this->start === 0) {
             return;
         }
         $diff = microtime(true) - $this->start;
         $this->totalTime += $diff;
         $this->curTickTotal += $diff;
         $this->count++;
         $this->start = 0;
         if ($this->parent instanceof TimingsHandler) {
             $this->parent->stopTiming();
         }
     }
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:16,代码来源:TimingsHandler.php

示例2: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.enable"));
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.disable"));
         return true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsDisabled"));
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.reset"));
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!file_exists($timingFolder)) {
             mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
             curl_setopt($ch, CURLOPT_HEADER, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
                 return true;
             }
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $matches[1] . "/"]));
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", ["http://timings.aikar.co/?url=" . $matches[1]]));
             fclose($fileTimings);
         } else {
             fclose($fileTimings);
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsWrite", [$timings]));
         }
     }
     return true;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:73,代码来源:TimingsCommand.php

示例3: tick

 /**
  * Tries to execute a server tick
  */
 private function tick()
 {
     $tickTime = microtime(true);
     if ($tickTime - $this->nextTick < -0.025) {
         //Allow half a tick of diff
         return false;
     }
     Timings::$serverTickTimer->startTiming();
     ++$this->tickCounter;
     $this->checkConsole();
     Timings::$connectionTimer->startTiming();
     $this->network->processInterfaces();
     if ($this->rcon !== null) {
         $this->rcon->check();
     }
     Timings::$connectionTimer->stopTiming();
     Timings::$schedulerTimer->startTiming();
     $this->scheduler->mainThreadHeartbeat($this->tickCounter);
     Timings::$schedulerTimer->stopTiming();
     $this->checkTickUpdates($this->tickCounter, $tickTime);
     foreach ($this->players as $player) {
         $player->checkNetwork();
     }
     if (($this->tickCounter & 0b1111) === 0) {
         $this->titleTick();
         $this->maxTick = 20;
         $this->maxUse = 0;
         if (($this->tickCounter & 0b111111111) === 0) {
             try {
                 $this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5));
                 if ($this->queryHandler !== null) {
                     $this->queryHandler->regenerateInfo();
                 }
             } catch (\Exception $e) {
                 if ($this->logger instanceof MainLogger) {
                     $this->logger->logException($e);
                 }
             }
         }
         $this->getNetwork()->updateName();
     }
     if ($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks) {
         $this->autoSaveTicker = 0;
         $this->doAutoSave();
     }
     if ($this->sendUsageTicker > 0 and --$this->sendUsageTicker === 0) {
         $this->sendUsageTicker = 6000;
         $this->sendUsage(SendUsageTask::TYPE_STATUS);
     }
     if ($this->tickCounter % 100 === 0) {
         foreach ($this->levels as $level) {
             $level->clearCache();
         }
         if ($this->getTicksPerSecondAverage() < 12) {
             $this->logger->warning($this->getLanguage()->translateString("pocketmine.server.tickOverload"));
         }
     }
     if ($this->dispatchSignals and $this->tickCounter % 5 === 0) {
         pcntl_signal_dispatch();
     }
     $this->getMemoryManager()->check();
     Timings::$serverTickTimer->stopTiming();
     $now = microtime(true);
     $tick = min(20, 1 / max(0.001, $now - $tickTime));
     $use = min(1, ($now - $tickTime) / 0.05);
     TimingsHandler::tick($tick <= $this->profilingTickRate);
     if ($this->maxTick > $tick) {
         $this->maxTick = $tick;
     }
     if ($this->maxUse < $use) {
         $this->maxUse = $use;
     }
     array_shift($this->tickAverage);
     $this->tickAverage[] = $tick;
     array_shift($this->useAverage);
     $this->useAverage[] = $use;
     if ($this->nextTick - $tickTime < -1) {
         $this->nextTick = $tickTime;
     } else {
         $this->nextTick += 0.05;
     }
     return true;
 }
开发者ID:ZenaGamingsky,项目名称:PocketBox,代码行数:86,代码来源:Server.php

示例4: tick

 /**
  * Tries to execute a server tick
  */
 private function tick()
 {
     $tickTime = microtime(true);
     if ($tickTime < $this->nextTick) {
         return false;
     }
     Timings::$serverTickTimer->startTiming();
     ++$this->tickCounter;
     $this->checkConsole();
     Timings::$connectionTimer->startTiming();
     $this->network->processInterfaces();
     Timings::$connectionTimer->stopTiming();
     Timings::$schedulerTimer->startTiming();
     $this->scheduler->mainThreadHeartbeat($this->tickCounter);
     Timings::$schedulerTimer->stopTiming();
     $this->checkTickUpdates($this->tickCounter);
     if (($this->tickCounter & 0b1111) === 0) {
         $this->titleTick();
         if ($this->queryHandler !== null and ($this->tickCounter & 0b111111111) === 0) {
             try {
                 $this->queryHandler->regenerateInfo();
             } catch (\Exception $e) {
                 if ($this->logger instanceof MainLogger) {
                     $this->logger->logException($e);
                 }
             }
         }
     }
     Timings::$generationTimer->startTiming();
     try {
         $this->generationManager->process();
     } catch (\Exception $e) {
         if ($this->logger instanceof MainLogger) {
             $this->logger->logException($e);
         }
     }
     Timings::$generationTimer->stopTiming();
     if ($this->tickCounter % 100 === 0) {
         foreach ($this->levels as $level) {
             $level->clearCache();
         }
     }
     Timings::$serverTickTimer->stopTiming();
     TimingsHandler::tick();
     $now = microtime(true);
     array_shift($this->tickAverage);
     $this->tickAverage[] = min(20, 1 / max(0.001, $now - $tickTime));
     array_shift($this->useAverage);
     $this->useAverage[] = min(1, ($now - $tickTime) / 0.05);
     if ($this->nextTick - $tickTime < -1) {
         $this->nextTick = $tickTime;
     }
     $this->nextTick += 0.05;
     return true;
 }
开发者ID:ZenaGamingsky,项目名称:Steadfast2,代码行数:58,代码来源:Server.php

示例5: reload

 public function reload()
 {
     $this->logger->info("Saving levels...");
     foreach ($this->levels as $level) {
         $level->save();
     }
     $this->pluginManager->disablePlugins();
     $this->pluginManager->clearPlugins();
     $this->commandMap->clearCommands();
     $this->logger->info("Reloading properties...");
     $this->properties->reload();
     $this->advancedConfig->reload();
     $this->loadAdvancedConfig();
     $this->maxPlayers = $this->getConfigInt("max-players", 20);
     if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) {
         $this->setConfigInt("difficulty", 3);
     }
     $this->banByIP->load();
     $this->banByName->load();
     $this->banByCID->load();
     $this->reloadWhitelist();
     $this->operators->reload();
     $this->memoryManager->doObjectCleanup();
     foreach ($this->getIPBans()->getEntries() as $entry) {
         $this->getNetwork()->blockAddress($entry->getName(), -1);
     }
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->registerInterface(FolderPluginLoader::class);
     $this->pluginManager->registerInterface(ScriptPluginLoader::class);
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     TimingsHandler::reload();
 }
开发者ID:xuxugzs,项目名称:Genisys,代码行数:34,代码来源:Server.php

示例6: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \true;
     }
     $mode = \strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(\true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return \true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(\false);
         $sender->sendMessage("Disabled Timings");
         return \true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return \true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = \microtime(\true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!\file_exists($timingFolder)) {
             \mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (\file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? \fopen("php://temp", "r+b") : \fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         \fwrite($fileTimings, "Sample time " . \round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . \PHP_EOL);
         if ($paste) {
             \fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => \stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, \false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, \false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, \false);
             curl_setopt($ch, CURLOPT_HEADER, \true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, \true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (\preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return \true;
             }
             $sender->sendMessage("Timings uploaded to http://paste.ubuntu.com/" . $matches[1] . "/");
             $sender->sendMessage("You can read the results at http://timings.aikar.co/?url=" . $matches[1]);
             \fclose($fileTimings);
         } else {
             \fclose($fileTimings);
             $sender->sendMessage("Timings written to " . $timings);
         }
     }
     return \true;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:73,代码来源:TimingsCommand.php

示例7: pasteTimings

 private function pasteTimings()
 {
     $sampleTime = microtime(true) - TimingsCommand::$timingStart;
     $ft = fopen("php://temp", "r+b");
     TimingsHandler::printTimings($ft);
     fwrite($ft, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
     fseek($ft, 0);
     $data = ["syntax" => "text", "poster" => "LegionPE", "content" => stream_get_contents($ft)];
     $ch = curl_init("http://paste.ubuntu.com/");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_AUTOREFERER, false);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: LegionPE " . $this->getDescription()->getVersion()]);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $data = curl_exec($ch);
     curl_close($ch);
     if (preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
         return "about:blank";
     }
     fclose($ft);
     return "http://timings.aikar.co/?url={$matches['1']}";
 }
开发者ID:LegionPE,项目名称:LegionPE-Eta,代码行数:28,代码来源:LegionPE.php

示例8: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage("Disabled Timings");
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         @mkdir($timingFolder, 0777);
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["public" => false, "description" => $sender->getServer()->getName() . " Timings", "files" => ["timings.txt" => ["content" => stream_get_contents($fileTimings)]]];
             $ch = curl_init("https://api.github.com/gists");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES));
             curl_setopt($ch, CURLOPT_AUTOREFERER, true);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json", "User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $ret = curl_exec($ch);
             $data = json_decode($ret);
             curl_close($ch);
             if ($data === false or $data === null or !isset($data->html_url)) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return true;
             }
             $timings = $data->html_url;
         }
         fclose($fileTimings);
         $sender->sendMessage("Timings written to " . $timings);
         $sender->sendMessage("Paste contents of file into form at http://aikar.co/timings.php to read results.");
     }
     return true;
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:68,代码来源:TimingsCommand.php

示例9: stopTiming

 public function stopTiming()
 {
     if (PluginManager::$useTimings) {
         if (--$this->timingDepth !== 0 or $this->start === 0) {
             return;
         }
         $diff = \microtime(\true) - $this->start;
         $this->totalTime += $diff;
         $this->curTickTotal += $diff;
         ++$this->curCount;
         ++$this->count;
         $this->start = 0;
         if ($this->parent !== \null) {
             $this->parent->stopTiming();
         }
     }
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:17,代码来源:TimingsHandler.php

示例10: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $tickDiff = max(1, $currentTick - $this->lastUpdate);
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->updateMovement();
     $this->timings->stopTiming();
     //if($this->isStatic())
     return $hasUpdate;
     //return !($this instanceof Player);
 }
开发者ID:RedstoneAlmeida,项目名称:Steadfast2,代码行数:15,代码来源:Entity.php

示例11: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     if (!$this->isAlive()) {
         ++$this->deadTicks;
         if ($this->deadTicks >= 10) {
             $this->despawnFromAll();
             if (!$this->isPlayer) {
                 $this->close();
             }
         }
         return $this->deadTicks < 10;
     }
     $tickDiff = $currentTick - $this->lastUpdate;
     if ($tickDiff <= 0) {
         return false;
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->updateMovement();
     $this->timings->stopTiming();
     //if($this->isStatic())
     return $hasUpdate;
     //return !($this instanceof Player);
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:28,代码来源:Entity.php

示例12: __destruct

 public function __destruct()
 {
     $this->timings->remove();
 }
开发者ID:zzz1999,项目名称:ImagicalMine,代码行数:4,代码来源:RegisteredListener.php

示例13: remove

 public function remove()
 {
     $this->cancelled = true;
     $this->task->setHandler(null);
     $this->timings->remove();
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:6,代码来源:TaskHandler.php


注:本文中的pocketmine\event\TimingsHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。