query("SELECT 1 FROM books LIMIT 1"); } catch (\PDOException $e) { $healthy = false; error_log("healthz: calibre db check failed: " . $e->getMessage()); } // Test main database (via ORM/Db) try { Db::pdo()->query("SELECT 1"); } catch (\PDOException $e) { $healthy = false; error_log("healthz: main db check failed: " . $e->getMessage()); } $response = (new Response()) ->withHeader("Content-Type", "application/json") ->withBody(json_encode(["status" => $healthy ? "ok" : "error"])); if (!$healthy) { $response = $response->withStatus(503); } return $response; } }