<?php
declare(strict_types=1);

require __DIR__ . '/../includes/lib/server_status.php';

$targets = [
    ['url' => 'https://example.com'],
    ['url' => 'https://example.com/does-not-exist-hopefully'],
    ['url' => 'https://fabianschieder.com/nextcloud'],
];

foreach ($targets as $t) {
    $r = check_http_head($t['url']);
    echo $t['url'], " => ", ($r['ok'] ? 'UP' : 'DOWN'), " code=", ($r['code'] ?? 'null'), " ms=", ($r['ms'] ?? 'null');
    if (!empty($r['error'])) {
        echo " error=", $r['error'];
    }
    echo PHP_EOL;

    // Zusatz: expliziter GET-Check (ohne Redirects), um 301/302 vs. 5xx besser zu sehen.
    $g = check_http_request($t['url'], 'GET', 2.5, "Range: bytes=0-0\r\n");
    echo "  GET  => ", ($g['ok'] ? 'UP' : 'DOWN'), " code=", ($g['code'] ?? 'null'), " ms=", ($g['ms'] ?? 'null');
    if (!empty($g['error'])) {
        echo " error=", $g['error'];
    }
    echo PHP_EOL;
}
