PHP code example of pjz9n / pterodactyl-php-sdk

1. Go to this page and download the library: Download pjz9n/pterodactyl-php-sdk 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/ */

    

pjz9n / pterodactyl-php-sdk example snippets




declare(strict_types=1);

om/api";
$key = "API Key";

$clientAPI = new \PJZ9n\PterodactylSDK\ClientAPI($url, $key);

echo "Server Counts: ";
try {
    echo count($clientAPI->getServers()) . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

$serverID = "1ab234c5";

echo "Start Server" . PHP_EOL;
try {
    $clientAPI->sendPowerAction($serverID, \PJZ9n\PterodactylSDK\Variables\PowerAction\PowerAction::POWERACTION_START);
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

echo "Server Memory Limit: ";
try {
    echo $clientAPI->getResource($serverID)->getMemory()->getLimit() . "MB" . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

/*
 * Result
 * 
 * Server Counts: 100
 * Start Server
 * Server Memory Limit: 1000MB
 */



declare(strict_types=1);

om/api";
$key = "API Key";

$clientAPI = new \PJZ9n\PterodactylSDK\ClientAPI($url, $key);

echo "Server Counts: ";
try {
    echo count($clientAPI->getServers()) . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

$serverID = "1ab234c5";

echo "Start Server" . PHP_EOL;
try {
    $clientAPI->sendPowerAction($serverID, \PJZ9n\PterodactylSDK\Variables\PowerAction\PowerAction::POWERACTION_START);
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

echo "Server Memory Limit: ";
try {
    echo $clientAPI->getResource($serverID)->getMemory()->getLimit() . "MB" . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

/*
 * 結果
 * 
 * Server Counts: 100
 * Start Server
 * Server Memory Limit: 1000MB
 */
shell script
composer 
shell script
composer