Add detailed logging for health requests in health.php and enhance entrypoint.sh with Apache configuration logging

This commit is contained in:
2026-05-23 13:04:43 +02:00
parent eff0aeb8c3
commit 587eb4502a
2 changed files with 46 additions and 0 deletions
+35
View File
@@ -6,13 +6,43 @@ header('Content-Type: application/json; charset=utf-8');
require __DIR__ . '/config.php';
// #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
try {
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'),
]);
if (!extension_loaded('pdo_pgsql')) {
throw new RuntimeException('pdo_pgsql extension missing');
}
require_once __DIR__ . '/helpers.php';
require_database();
$response = ['status' => 'ok'];
agent_debug_health_request_log('H5,H7', 'health request returning ok', [
'exit_code' => 0,
'response' => $response,
]);
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
http_response_code(503);
@@ -20,6 +50,11 @@ try {
'status' => 'error',
'message' => $e->getMessage(),
];
agent_debug_health_request_log('H5,H7', 'health request returning error', [
'exit_code' => 1,
'response' => $response,
'error_class' => get_class($e),
]);
echo json_encode($response, JSON_UNESCAPED_UNICODE);
exit(1);
}