WoW Shrine
Keep your hearthstone set to Shrine!
You're browsing our forum as a Guest meaning you can only see a portion of the forum in read-only mode. To view all forum nodes and be able to create threads/posts please register or log-in.
Events Updates Discord Wrath x5 WotLK server WTS WTB

WoW server uptime script PHP for TrinityCore

0 Members and 1 Guest are viewing this topic.

WoW server uptime script PHP for TrinityCore
« on: April 13, 2022, 02:18:38 AM »
WoW server uptime script in PHP using PDO for TrinityCore.


<?php
   // WoW server uptime and max. players
   $query_uptime_wotlk = "SELECT starttime, maxplayers FROM uptime WHERE realmid = '1' ORDER BY starttime DESC LIMIT 1";
   $query_con_uptime_wotlk = $conn -> prepare($query_uptime_wotlk);
   $query_con_uptime_wotlk->execute();
   $res_uptime_wotlk = $query_con_uptime_wotlk->fetch(PDO::FETCH_ASSOC);
   
   $uptimetime = time() - $res_uptime_wotlk['starttime'];
   
   function format_uptime($seconds) {
      $secs  = intval($seconds % 60);
      $mins  = intval($seconds / 60 % 60);
      $hours = intval($seconds / 3600 % 24);
      $days  = intval($seconds / 86400);

      $uptimeString='';

      if ($days) {
         $uptimeString .= $days;
         $uptimeString .= ((1 === $days) ? ' day' : ' days');
      }
      if ($hours) {
         $uptimeString .= ((0 < $days) ? ', ' : '').$hours;
         $uptimeString .= ((1 === $hours) ? ' hour' : ' hours');
      }
      if ($mins) {
         $uptimeString .= ((0 < $days || 0 < $hours) ? ', ' : '').$mins;
         $uptimeString .= ((1 === $mins) ? ' minute' : ' minutes');
      }
      if ($secs) {
         $uptimeString .= ((0 < $days || 0 < $hours || 0 < $mins) ? ', ' : '').$secs;
         $uptimeString .= ((1 === $secs) ? ' second' : ' seconds');
      }
      return $uptimeString;
   }
   
   $staticUptime = format_uptime($uptimetime);
   unset($uptimetime);
   
   echo "
   <div>
      <span style=\"font-size:0.8em;color:#B0BEC5;\">Uptime: ".$staticUptime."</span><br />
      <span style=\"font-size:0.8em;color:#B0BEC5;\">Max. players: ".$res_uptime_wotlk[maxplayers]."</span>
   </div>
";
   
   unset($staticUptime);
   unset($query_con_uptime_wotlk);
?>





--
« Last Edit: April 13, 2022, 02:24:44 AM by FengShui »
 





Partners
WoW Database