PHP code example of multiplayer-gratis / api-client

1. Go to this page and download the library: Download multiplayer-gratis/api-client 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/ */

    

multiplayer-gratis / api-client example snippets


use MultiplayerGratis\Client;

$client = new Client(getenv('MULTIPLAYER_GRATIS_API_KEY'));

// Konto mit Coin-Guthaben
$account = $client->getAccount();

// Alle Server
$servers = $client->getServers();

// Details & Status eines Servers
$server = $client->getServer(123);

// Auslastung: CPU, RAM, Speicher, Laufzeit
$resources = $client->getServerResources(123);

// Power-Aktionen
$client->startServer(123);
$client->stopServer(123);
$client->restartServer(123);
$client->killServer(123);   // sofort beenden

// oder generisch
use MultiplayerGratis\PowerSignal;
$client->sendPowerSignal(123, PowerSignal::Restart);

use MultiplayerGratis\Exception\ApiException;
use MultiplayerGratis\Exception\RateLimitException;

try {
    $client->restartServer(123);
} catch (RateLimitException $e) {
    sleep($e->getRetryAfter() ?? 60);
} catch (ApiException $e) {
    echo "Fehler {$e->getStatusCode()}: {$e->getMessage()}";
}

use MultiplayerGratis\Client;
use MultiplayerGratis\Http\CurlHttpClient;

$client = new Client($apiKey, http: new CurlHttpClient(timeout: 30, connectTimeout: 10));