Skip to content

Resources: Servers

Danny Li edited this page Apr 3, 2018 · 3 revisions

Special methods

Server object

The Server object has the following methods:

<?php
use Exploriment\HetznerCloud;

// retrieve the server
$server = HetznerCloud\Servers::find(1);

// returns the server ID (int)
$server->getId();

// returns the server name (string)
$server->getName();

// returns the server status (string)
$server->getStatus();

// status = running? (boolean)
$server->isRunning();

// status = initializing? (boolean)
$server->isInitializing();

// status = starting? (boolean)
$server->isStarting();

// status = stopping? (boolean)
$server->isStopping();

// status = off? (boolean)
$server->isOff();

// status = deleting? (boolean)
$server->isDeleting();

// status = migrating? (boolean)
$server->isMigrating();

// status = rebuilding? (boolean)
$server->isRebuilding();

// status = unknown? (boolean)
$server->isUnknown();

// returns the time when the server was created (string)
$server->getCreated();

// returns public network information (object)
$net = $server->getPublicNet();

// returns ipv4 information (object)
$ipv4 = $net->getIpv4();
$ipv4->ip; // string
$ipv4->blocked; // boolean
$ipv4->dns_ptr; // string

// returns ipv6 information (object)
$ipv6 = $net->getIpv6();
$ipv6->ip; // string
$ipv6->blocked; // boolean
$ipv6->dns_ptr; // array

// returns assigned floating ips ids (array)
$net->getFloatingIps();

/**
 * returns the server type
 * @return https://github.com/Exploriment/hcloud-php/wiki/resources:-servertypes#servertype-object
 */
$server->getServerType();

/**
 * returns the datacenter the server is located at
 * @return https://github.com/Exploriment/hcloud-php/wiki/resources:-datacenters#datacenter-object
 */
$server->getDatacenter();

/**
 * returns the image the server was created from
 * @return null or https://github.com/Exploriment/hcloud-php/wiki/resources:-images#image-object
 */
$server->getImage();

/**
 * returns the ISO image that is attached to this server
 * @return null or https://github.com/Exploriment/hcloud-php/wiki/resources:-locations#location-object
 */
$server->getIso();

// is rescue mode enabled? (boolean)
$server->isRescueEnabled();

// is the server locked and unavailable to the user?
$server->isLocked();

// retrieve the backup window hours (UTC) (null or string)
$server->getBackupWindow();

// retrieve the outgoing traffic in bytes (int or null)
$server->getOutgoingTraffic();

// retrieve the ingoing traffic in bytes (int or null)
$server->getIngoingTraffic();

// calculate the remaining free traffic in byetes (int)
// 0 outgoing traffic is assumed if $server->getOutgoingTraffic() returns null
$server->getRemainingTraffic();

/**
 * All the special methods mentioned above are available in the server object
 * too. The method names are exactly the same, so are the parameters, except
 * for the server ID, which can be omitted. A few examples below:
 *
 * @example $server->findAction($action_id);
 * @example $server->start();
 * @example $server->changePtr($ip, $dns_ptr);
 */
Clone this wiki locally