<?php
    // Start the session
    session_start();

    if (!isset($_SESSION["preSendCount"])) {
        $_SESSION["preSendCount"] = 0;
    }

    if (!isset($_SESSION["refreshState"])) {
        $_SESSION["refreshState"] = "false";
    }

    // $host = "http://www.itdominatorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.com";
    $host = "itdominator.com";
    if($socket =@ fsockopen($host, 80, $errno, $errstr, 35)) {
        fclose($socket);
        $_SESSION["preSendCount"] = 0;
        $_SESSION["refreshState"] = "false";
    } else {
        if($socket =@ fsockopen("google.com", 80, $errno, $errstr, 65)) {
            fclose($socket);
            if ($_SESSION["preSendCount"] == 2) {
                $_SESSION["refreshState"] = "true";
            } else {
                $_SESSION["preSendCount"] ++;
           }
       } else {
           $_SESSION["refreshState"] = "networkDown";
       }
    }

    header('Content-Type: text/event-stream');
    header('Cache-Control: no-cache');
    echo "data:" . $_SESSION["refreshState"] . "\n\n";
    flush();
?>
