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


PHP TimingsHandler::printTimings方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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


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