PHP code example of minicodemonkey / hetzner-robot

1. Go to this page and download the library: Download minicodemonkey/hetzner-robot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

minicodemonkey / hetzner-robot example snippets


use Hetzner\Robot\Client;

$robot = new Client('https://robot-ws.your-server.de', 'login', 'password');

// retrieve all failover ips
$results = $robot->failoverGet();

foreach ($results as $result)
{
  echo $result->failover->ip . "\n";
  echo $result->failover->server_ip . "\n";
  echo $result->failover->active_server_ip . "\n";
}

// retrieve a specific failover ip
$result = $robot->failoverGet('123.123.123.123');

echo $result->failover->ip . "\n";
echo $result->failover->server_ip . "\n";
echo $result->failover->active_server_ip . "\n";

// switch routing
try
{
  $robot->failoverRoute('123.123.123.123', '213.133.104.190');
}
catch (RobotClientException $e)
{
  echo $e->getMessage() . "\n";
}