Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d02e4311dd |
+33
-47
@@ -1,50 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
// Health check endpoint - returns number of tables in thetool database
|
||||||
* Health Check Endpoint
|
|
||||||
* Returns application health status and database connectivity
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// Define required constants before loading config
|
||||||
|
define('FRONKDB_SQLDEBUG', false);
|
||||||
|
|
||||||
|
// Load the framework's database configuration
|
||||||
|
require_once(__DIR__ . "/../../config/config.php");
|
||||||
|
|
||||||
|
// Load the autoloader to get FronkDB class
|
||||||
|
require_once(__DIR__ . "/../../lib/autoloader/autoloader.php");
|
||||||
|
require_once(__DIR__ . "/../../lib/mvcfronk/mfLog/mfLoghandler.php");
|
||||||
|
require_once(__DIR__ . "/../../lib/FronkDB/FronkDB.php");
|
||||||
|
|
||||||
|
// Connect to the database using the framework's configuration
|
||||||
|
$db = new FronkDB(
|
||||||
|
FRONKDB_DBHOST,
|
||||||
|
FRONKDB_DBUSER,
|
||||||
|
FRONKDB_DBPASS,
|
||||||
|
FRONKDB_DBNAME
|
||||||
|
);
|
||||||
|
|
||||||
|
// Query to count tables in the thetool database
|
||||||
|
$sql = "SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'thetool'";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$row = $db->fetch_array($result);
|
||||||
|
$tableCount = (int)$row['count'];
|
||||||
|
} else {
|
||||||
|
$tableCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return JSON response
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['tables' => $tableCount]);
|
||||||
$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);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user