Files
thetool/public/api/health.php
AI Development Engine 1fdfcd635f feat: implement issue #4
Resolves luca/thetool#4
Closes #4
2026-03-02 10:09:47 +00:00

51 lines
858 B
PHP

<?php
/**
* Health Check Endpoint
* Returns application health status and database connectivity
*/
header('Content-Type: application/json');
$health = [
'status' => 'ok',
'timestamp' => time()
];
// Check database connection
$dbConnected = false;
$dbError = null;
try {
$conn = @mysqli_connect(
'aide-mariadb',
'aide',
'aide',
'thetool_s13'
);
if ($conn) {
$dbConnected = true;
mysqli_close($conn);
}
} catch (Exception $e) {
$dbError = $e->getMessage();
}
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);