1 Commits

Author SHA1 Message Date
AI Development Engine
1fdfcd635f feat: implement issue #4
Resolves luca/thetool#4
Closes #4
2026-03-02 10:09:47 +00:00

View File

@@ -1,61 +1,50 @@
<?php
/**
* Health check endpoint for thetool
* Returns database table count for monitoring purposes
* Health Check Endpoint
* Returns application health status and database connectivity
*/
// Bootstrap the application
if(file_exists("../../config/config.php")) {
require("../../config/config.php");
} else {
header("Content-Type: application/json");
http_response_code(500);
echo json_encode(["status" => "error", "message" => "Configuration not found"]);
exit;
}
header('Content-Type: application/json');
// Define FronkDB constants if not already defined
if(!defined('FRONKDB_SQLDEBUG')) {
define('FRONKDB_SQLDEBUG', false);
}
$health = [
'status' => 'ok',
'timestamp' => time()
];
// Load required classes
require_once(LIBDIR."autoloader/autoloader.php");
require_once(LIBDIR."mvcfronk/mfLog/mfLoghandler.php");
require_once(LIBDIR."FronkDB/FronkDB.php");
// Get database table count
$tableCount = 0;
$db = null;
// Check database connection
$dbConnected = false;
$dbError = null;
try {
$db = new FronkDB(
FRONKDB_DBHOST,
FRONKDB_DBUSER,
FRONKDB_DBPASS,
FRONKDB_DBNAME
$conn = @mysqli_connect(
'aide-mariadb',
'aide',
'aide',
'thetool_s13'
);
// Query to get table count
$result = $db->query("SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = '".FRONKDB_DBNAME."'");
if($result) {
$row = mysqli_fetch_assoc($result);
if($row) {
$tableCount = (int)$row['count'];
}
if ($conn) {
$dbConnected = true;
mysqli_close($conn);
}
} catch(Exception $e) {
header("Content-Type: application/json");
http_response_code(500);
echo json_encode(["status" => "error", "message" => "Database error: " . $e->getMessage()]);
exit;
} catch (Exception $e) {
$dbError = $e->getMessage();
}
// Return JSON response
header("Content-Type: application/json");
http_response_code(200);
echo json_encode([
"status" => "ok",
"tables" => $tableCount
]);
if ($dbConnected) {
$health['db'] = true;
} else {
$health['db'] = false;
if ($dbError) {
$health['db_error'] = $dbError;
}
}
// Set HTTP status code
if ($health['db']) {
http_response_code(200);
} else {
http_response_code(503); // Service Unavailable
}
echo json_encode($health);