prepare('SELECT * FROM `jobs`'); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $rowCount = $stmt->rowCount(); if ($rowCount > 0) { echo "[Job Checker] " . $rowCount . " Servers Found\n"; foreach ($rows as $row) { echo isUp($row["soapport"]) . PHP_EOL; if (!isUp($row["soapport"]) && (time() - $row["startTime"]) > 10) { $port = $row["pid"] ?? 0; $soapUtils->killRcc($port); $port = $row["soapport"] ?? 0; $stmt = $pdo->prepare('DELETE FROM `jobs` WHERE `soapport` = :port'); $stmt->bindParam(":port", $port, PDO::PARAM_INT); $stmt->execute(); echo "[Job Deleter] Deleted 1 Broken Server(s)\n"; } } } else { echo "[Job Checker] No Running Servers Found\n"; } $rccs = $soapUtils->getAllRccs(); foreach ($rccs as $rcc) { $stmt = $pdo->prepare("SELECT * FROM `jobs` WHERE `pid` = :pid"); $stmt->bindParam(":pid", $rcc["pid"], PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() < 1) { if (!isset($activeRuntimes[$rcc["pid"]])) { echo "start runtime" . PHP_EOL; $runtime = new Runtime(); $future = $runtime->run(function ($pid) { include_once __DIR__ . '/config/main.php'; $retries = 0; do { $stmt = $pdo->prepare("SELECT * FROM `jobs` WHERE `pid` = :pid"); $stmt->bindParam(":pid", $pid, PDO::PARAM_INT); $stmt->execute(); $count = $stmt->rowCount(); $retries++; if ($count >= 1) { echo "job found!" . PHP_EOL; return; } sleep(1); } while ($count < 1 && $retries < 60); echo "jobless rcc found" . PHP_EOL; (new SoapUtils())->killRcc($pid); }, [$rcc["pid"]]); $activeRuntimes[$rcc["pid"]] = $future; } } else { $result = $stmt->fetch(PDO::FETCH_ASSOC); if ($result["isRenderer"] == 0) { $playerCount = $soapUtils->getPlayerCount($result["soapport"], $result["jobid"]); if ($playerCount == 0) { if (!isset($activeRuntimes[$rcc["pid"]])) { $runtime = new Runtime(); $future = $runtime->run(function ($pid) { include_once __DIR__ . '/config/main.php'; $soapUtils = new SoapUtils(); $retries = 0; do { $stmt = $pdo->prepare("SELECT * FROM `jobs` WHERE `pid` = :pid"); $stmt->bindParam(":pid", $pid, PDO::PARAM_INT); $stmt->execute(); $playerCount = $soapUtils->getPlayerCount($result["soapport"], $result["jobid"]); $retries++; sleep(1); } while ($playerCount < 1 && $retries < 10); if ($playerCount >= 1) { return; } echo "rcc with 0 players found" . PHP_EOL; $stmt = $pdo->prepare('DELETE FROM `jobs` WHERE `soapport` = :soapport'); $stmt->bindParam(":soapport", $result["soapport"], PDO::PARAM_INT); $stmt->execute(); (new SoapUtils())->killRcc($pid); }, [$rcc["pid"]]); $activeRuntimes[$rcc["pid"]] = $future; } } } else { if (!isset($activeRuntimes[$rcc["pid"]])) { $runtime = new Runtime(); $future = $runtime->run(function ($pid) { include_once __DIR__ . '/config/main.php'; $retries = 0; do { $stmt = $pdo->prepare("SELECT * FROM `jobs` WHERE `pid` = :pid"); $stmt->bindParam(":pid", $pid, PDO::PARAM_INT); $stmt->execute(); $count = $stmt->rowCount(); $retries++; sleep(1); } while ($count >= 1 && $retries < 10); echo "jobless rcc found" . PHP_EOL; $stmt = $pdo->prepare('DELETE FROM `jobs` WHERE `soapport` = :soapport'); $stmt->bindParam(":soapport", $result["soapport"], PDO::PARAM_INT); $stmt->execute(); (new SoapUtils())->killRcc($pid); }, [$rcc["pid"]]); $activeRuntimes[$rcc["pid"]] = $future; } } } } foreach ($activeRuntimes as $key => $future) { if ($future->done()) { unset($activeRuntimes[$key]); } } usleep(100_000); }