2026-05-23 12:43:51 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Container health check (Coolify / Docker HEALTHCHECK).
|
|
|
|
|
*/
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
|
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
|
|
2026-05-23 13:04:43 +02:00
|
|
|
// #region agent log
|
|
|
|
|
function agent_debug_health_request_log(string $hypothesisId, string $message, array $data = []): void {
|
|
|
|
|
$payload = [
|
|
|
|
|
'sessionId' => '885d37',
|
|
|
|
|
'runId' => 'coolify-bad-gateway',
|
|
|
|
|
'hypothesisId' => $hypothesisId,
|
|
|
|
|
'location' => 'health.php',
|
|
|
|
|
'message' => $message,
|
|
|
|
|
'data' => $data,
|
|
|
|
|
'timestamp' => (int) round(microtime(true) * 1000),
|
|
|
|
|
];
|
|
|
|
|
$line = json_encode($payload, JSON_UNESCAPED_SLASHES) . PHP_EOL;
|
|
|
|
|
@file_put_contents(__DIR__ . '/debug-885d37.log', $line, FILE_APPEND);
|
|
|
|
|
@error_log('agent_debug ' . $line);
|
|
|
|
|
}
|
|
|
|
|
// #endregion
|
|
|
|
|
|
2026-05-23 12:43:51 +02:00
|
|
|
try {
|
2026-05-23 13:04:43 +02:00
|
|
|
agent_debug_health_request_log('H5,H7', 'health request reached PHP', [
|
|
|
|
|
'sapi' => PHP_SAPI,
|
|
|
|
|
'request_uri' => $_SERVER['REQUEST_URI'] ?? '',
|
|
|
|
|
'http_host' => $_SERVER['HTTP_HOST'] ?? '',
|
|
|
|
|
'server_port' => $_SERVER['SERVER_PORT'] ?? '',
|
|
|
|
|
'database_url_getenv_present' => getenv('DATABASE_URL') !== false && getenv('DATABASE_URL') !== '',
|
|
|
|
|
'database_url_server_present' => isset($_SERVER['DATABASE_URL']) && $_SERVER['DATABASE_URL'] !== '',
|
|
|
|
|
'dot_env_file_exists' => file_exists(__DIR__ . '/.env'),
|
|
|
|
|
]);
|
2026-05-23 12:43:51 +02:00
|
|
|
if (!extension_loaded('pdo_pgsql')) {
|
|
|
|
|
throw new RuntimeException('pdo_pgsql extension missing');
|
|
|
|
|
}
|
|
|
|
|
require_once __DIR__ . '/helpers.php';
|
|
|
|
|
require_database();
|
|
|
|
|
$response = ['status' => 'ok'];
|
2026-05-23 13:04:43 +02:00
|
|
|
agent_debug_health_request_log('H5,H7', 'health request returning ok', [
|
|
|
|
|
'exit_code' => 0,
|
|
|
|
|
'response' => $response,
|
|
|
|
|
]);
|
2026-05-23 12:43:51 +02:00
|
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
http_response_code(503);
|
|
|
|
|
$response = [
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
|
];
|
2026-05-23 13:04:43 +02:00
|
|
|
agent_debug_health_request_log('H5,H7', 'health request returning error', [
|
|
|
|
|
'exit_code' => 1,
|
|
|
|
|
'response' => $response,
|
|
|
|
|
'error_class' => get_class($e),
|
|
|
|
|
]);
|
2026-05-23 12:43:51 +02:00
|
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|