Check Minecraft status with PHP
Copy this example, set an optional MINECRAFTSTATUS_API_KEY in the environment, and pass an edition plus address. The example preserves pending, quota and freshness boundaries.
Source
<?php
declare(strict_types=1);
$base = getenv('MINECRAFTSTATUS_API_BASE') ?: 'https://minecraftstatus.com';
$edition = $argv[1] ?? 'java';
$address = $argv[2] ?? 'play.example.net';
$headers = ['Accept: application/json'];
if (($key = getenv('MINECRAFTSTATUS_API_KEY')) !== false && $key !== '') {
$headers[] = 'Authorization: Bearer ' . $key;
}
$handle = curl_init($base . '/api/v1/status/' . rawurlencode($edition) . '?address=' . rawurlencode($address));
curl_setopt_array($handle, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_TIMEOUT => 15]);
$raw = curl_exec($handle);
$status = (int) curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
if ($raw === false) throw new RuntimeException(curl_error($handle));
curl_close($handle);
$body = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
if ($status === 429) throw new RuntimeException('Rate limited; retry after ' . ($body['retryAfterSeconds'] ?? 'the Retry-After header') . ' seconds');
if ($status === 202) { echo "Observation pending: " . ($body['pollUrl'] ?? 'missing poll URL') . PHP_EOL; exit(0); }
if ($status >= 400) throw new RuntimeException('MinecraftStatus API HTTP ' . $status . ': ' . ($body['error']['message'] ?? 'request failed'));
echo json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
if (($body['freshness'] ?? null) !== 'fresh') fwrite(STDERR, "Current claim is not fresh; observe again before presenting it as current.\n");
Run with an address argument such as java play.example.net. The source files are versioned alongside this documentation under examples/api/php/status.php.
Choose another language
Contract boundary
Every example branches on HTTP status first, prints a queued job receipt for 202, respects Retry-After for 429, and refuses to present stale or missing freshness as current.