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


PHP Scalr_Util_DateTime::getHumanReadableTimeout方法代码示例

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


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

示例1: xListServersUpdateAction

 /**
  * Update server's information
  *
  * @param jsonData $servers optional List of servers to check against
  * @throws \Scalr_Exception_InsufficientPermissions
  */
 public function xListServersUpdateAction(JsonData $servers = null)
 {
     if (!$this->request->isAllowed([Acl::RESOURCE_FARMS, Acl::RESOURCE_TEAM_FARMS, Acl::RESOURCE_OWN_FARMS]) && !$this->request->isAllowed(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE)) {
         throw new \Scalr_Exception_InsufficientPermissions();
     }
     $props = $retval = [];
     $args = $servers = (array) $servers;
     $stmt = "\n            SELECT s.server_id, s.status, s.remote_ip, s.local_ip, s.dtadded, s.dtinitialized AS uptime\n            FROM servers s\n            LEFT JOIN farms f ON f.id = s.farm_id\n            WHERE s.server_id IN (" . implode(",", array_fill(0, count($servers), "?")) . ")\n            AND s.env_id = ?\n        ";
     $args[] = $this->getEnvironmentId();
     $where = ["s.farm_id IS NOT NULL AND " . $this->request->getFarmSqlQuery()];
     if ($this->request->isAllowed(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE)) {
         $where[] = "s.farm_id IS NULL AND s.status IN (?, ?)";
         $args[] = Entity\Server::STATUS_IMPORTING;
         $args[] = Entity\Server::STATUS_TEMPORARY;
     }
     $stmt .= " AND (" . join(" OR ", $where) . ")";
     if (!empty($servers)) {
         $srs = $this->db->Execute($stmt, $args);
         $neededProps = [Entity\Server::REBOOTING, Entity\Server::MISSING, Entity\Server::SZR_IS_INIT_FAILED, Entity\Server::LAUNCH_ERROR, Entity\Server::SZR_VESION];
         foreach (Entity\Server\Property::fetch($servers, $neededProps) as $resRow) {
             if (!array_key_exists($resRow->serverId, $props)) {
                 $props[$resRow->serverId] = [];
             }
             $props[$resRow->serverId][$resRow->name] = $resRow->value;
         }
         while ($server = $srs->FetchRow()) {
             if (!array_key_exists($server["server_id"], $props)) {
                 $props[$server["server_id"]] = [];
             }
             $status = $server["status"];
             if (in_array($status, [Entity\Server::STATUS_RUNNING, Entity\Server::STATUS_SUSPENDED])) {
                 if (array_key_exists(Entity\Server::REBOOTING, $props[$server["server_id"]]) && $props[$server["server_id"]][Entity\Server::REBOOTING] != 0) {
                     $server["status"] = "Rebooting";
                 }
                 if (array_key_exists(Entity\Server::MISSING, $props[$server["server_id"]]) && $props[$server["server_id"]][Entity\Server::MISSING] != 0) {
                     $server["status"] = "Missing";
                 }
             }
             if (array_key_exists(Entity\Server::SZR_IS_INIT_FAILED, $props[$server["server_id"]]) && $props[$server["server_id"]][Entity\Server::SZR_IS_INIT_FAILED] == 1 && in_array($server["status"], [Entity\Server::STATUS_INIT, Entity\Server::STATUS_PENDING])) {
                 $server["isInitFailed"] = 1;
             }
             if (array_key_exists(Entity\Server::LAUNCH_ERROR, $props[$server["server_id"]]) && $props[$server["server_id"]][Entity\Server::LAUNCH_ERROR] == 1) {
                 $server["launch_error"] = "1";
             }
             $server["agent_version"] = $props[$server["server_id"]][Entity\Server::SZR_VESION];
             if ($status === Entity\Server::STATUS_RUNNING) {
                 $server['uptime'] = \Scalr_Util_DateTime::getHumanReadableTimeout(time() - strtotime($server['uptime']), false);
             } else {
                 $server['uptime'] = '';
             }
             $retval[$server["server_id"]] = $server;
         }
     }
     $this->response->data(["servers" => $retval]);
 }
开发者ID:scalr,项目名称:scalr,代码行数:61,代码来源:Servers.php

示例2: getDateTimeDiff

 /**
  * Calculates difference between two dates.
  *
  * @param   DateTime|string      $value  DateTime object or string that represents time.
  * @param   bool                 $humanReadable Return number of seconds or human readable string
  * @return  string|int           Returns difference between dates.
  */
 public static function getDateTimeDiff($dateTime1, $dateTime2, $humanReadable = true)
 {
     if (!$dateTime1 instanceof DateTime) {
         $dateTime1 = new DateTime($dateTime1);
     }
     if (!$dateTime2 instanceof DateTime) {
         $dateTime2 = new DateTime($dateTime2);
     }
     $diff = $dateTime1->getTimestamp() - $dateTime2->getTimestamp();
     if ($humanReadable) {
         $diff = Scalr_Util_DateTime::getHumanReadableTimeout($diff);
     }
     return $diff;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:21,代码来源:DateTime.php

示例3: xListServersAction


//.........这里部分代码省略.........
     } else {
         //show servers related to role creation process only
         $sql .= ' AND servers.status IN (?, ?)';
         $args[] = SERVER_STATUS::IMPORTING;
         $args[] = SERVER_STATUS::TEMPORARY;
     }
     if ($this->getParam('farmRoleId')) {
         $sql .= " AND farm_roleid=?";
         $args[] = $this->getParam('farmRoleId');
     }
     if ($this->getParam('roleId')) {
         $sql .= " AND role_id=?";
         $args[] = $this->getParam('roleId');
     }
     if ($this->getParam('serverId')) {
         $sql .= " AND server_id=?";
         $args[] = $this->getParam('serverId');
     }
     if ($this->getParam('hideTerminated')) {
         $sql .= ' AND servers.status != ?';
         $args[] = SERVER_STATUS::TERMINATED;
     }
     $response = $this->buildResponseFromSql2($sql, array('platform', 'farm_name', 'role_name', 'role_alias', 'index', 'server_id', 'remote_ip', 'local_ip', 'uptime', 'status'), array('servers.server_id', 'farm_id', 'farms.name', 'remote_ip', 'local_ip', 'servers.status', 'farm_roles.alias'), $args);
     foreach ($response["data"] as &$row) {
         try {
             $dbServer = DBServer::LoadByID($row['server_id']);
             $row['cloud_server_id'] = $dbServer->GetCloudServerID();
             if (in_array($dbServer->status, array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT))) {
                 $row['cluster_role'] = "";
                 if ($dbServer->GetFarmRoleObject()->GetRoleObject()->getDbMsrBehavior() || $dbServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                     $isMaster = $dbServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) || $dbServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
                     $row['cluster_role'] = $isMaster ? 'Master' : 'Slave';
                     if ($isMaster && $dbServer->GetFarmRoleObject()->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER) || $dbServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER)) {
                         $row['cluster_role'] = 'Promoting';
                     }
                 }
             }
             $row['cloud_location'] = $dbServer->GetCloudLocation();
             if ($dbServer->platform == SERVER_PLATFORMS::EC2) {
                 $loc = $dbServer->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE);
                 if ($loc && $loc != 'x-scalr-diff') {
                     $row['cloud_location'] .= "/" . substr($loc, -1, 1);
                 }
             }
             if ($dbServer->platform == SERVER_PLATFORMS::EC2) {
                 $row['has_eip'] = $this->db->GetOne("SELECT id FROM elastic_ips WHERE server_id = ?", array($dbServer->serverId));
             }
             if ($dbServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MONGODB)) {
                 $shardIndex = $dbServer->GetProperty(Scalr_Role_Behavior_MongoDB::SERVER_SHARD_INDEX);
                 $replicaSetIndex = $dbServer->GetProperty(Scalr_Role_Behavior_MongoDB::SERVER_REPLICA_SET_INDEX);
                 $row['cluster_position'] = "{$shardIndex}-{$replicaSetIndex}";
             }
         } catch (Exception $e) {
         }
         $rebooting = $this->db->GetOne("SELECT value FROM server_properties WHERE server_id=? AND `name`=? LIMIT 1", array($row['server_id'], SERVER_PROPERTIES::REBOOTING));
         if ($dbServer->status == SERVER_STATUS::RUNNING) {
             if ($rebooting) {
                 $row['status'] = "Rebooting";
             }
             $subStatus = $dbServer->GetProperty(SERVER_PROPERTIES::SUB_STATUS);
             if ($subStatus) {
                 $row['status'] = ucfirst($subStatus);
             }
         }
         $row['is_locked'] = $dbServer->GetProperty(EC2_SERVER_PROPERTIES::IS_LOCKED) ? 1 : 0;
         $row['is_szr'] = $dbServer->IsSupported("0.5");
         $row['initDetailsSupported'] = $dbServer->IsSupported("0.7.181");
         if ($dbServer->GetProperty(SERVER_PROPERTIES::SZR_IS_INIT_FAILED) && in_array($dbServer->status, array(SERVER_STATUS::INIT, SERVER_STATUS::PENDING))) {
             $row['isInitFailed'] = 1;
         }
         $launchError = $dbServer->GetProperty(SERVER_PROPERTIES::LAUNCH_ERROR);
         if ($launchError) {
             $row['launch_error'] = "1";
         }
         $serverAlerts = new Alerts($dbServer);
         $row['agent_version'] = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_VESION);
         $row['agent_update_needed'] = $dbServer->IsSupported("0.7") && !$dbServer->IsSupported("0.7.189");
         $row['agent_update_manual'] = !$dbServer->IsSupported("0.5");
         $row['os_family'] = $dbServer->GetOsFamily();
         $row['flavor'] = $dbServer->GetFlavor();
         $row['alerts'] = $serverAlerts->getActiveAlertsCount();
         if (!$row['flavor']) {
             $row['flavor'] = '';
         }
         if ($dbServer->status == SERVER_STATUS::RUNNING) {
             $tm = (int) $dbServer->GetProperty(SERVER_PROPERTIES::INITIALIZED_TIME);
             if (!$tm) {
                 $tm = (int) strtotime($row['dtadded']);
             }
             if ($tm > 0) {
                 $row['uptime'] = Scalr_Util_DateTime::getHumanReadableTimeout(time() - $tm, false);
             }
         } else {
             $row['uptime'] = '';
         }
         $r_dns = $this->db->GetOne("SELECT value FROM farm_role_settings WHERE farm_roleid=? AND `name`=? LIMIT 1", array($row['farm_roleid'], DBFarmRole::SETTING_EXCLUDE_FROM_DNS));
         $row['excluded_from_dns'] = !$dbServer->GetProperty(SERVER_PROPERTIES::EXCLUDE_FROM_DNS) && !$r_dns ? false : true;
     }
     $this->response->data($response);
 }
开发者ID:recipe,项目名称:scalr,代码行数:101,代码来源:Servers.php


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