From d6d312f72f0cdae58e59ccdb6bae579e00bfdf9f Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:04:40 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20health.php=20respuesta=20instant=C3=A1ne?= =?UTF-8?q?a=20=E2=80=94=20sin=20DB=20ni=20Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Versión anterior intentaba conectar a DB (g1286...) y Redis (zqmfom0...) que colgaban esperando conexión → todos los workers PHP-FPM bloqueados → nginx acepta TCP pero no responde HTTP → healthcheck timeout → unhealthy. --- health.php | 100 +++-------------------------------------------------- 1 file changed, 5 insertions(+), 95 deletions(-) diff --git a/health.php b/health.php index 80fa823..b433d91 100644 --- a/health.php +++ b/health.php @@ -1,99 +1,9 @@ 'healthy', - 'timestamp' => date('Y-m-d H:i:s'), - 'checks' => [] -]; - -// 1. Check PHP -$health['checks']['php'] = [ - 'status' => 'ok', - 'version' => PHP_VERSION -]; - -// 2. Check Database -try { - require_once __DIR__ . '/config/config.php'; - $db = Database::getInstance(); - $result = $db->query("SELECT 1")->fetch(); - - $health['checks']['database'] = [ - 'status' => $result ? 'ok' : 'warning', - 'host' => DB_HOST - ]; -} catch (Exception $e) { - // DB caída = warning, no unhealthy — Traefik debe seguir ruteando - // (mejor mostrar error 500 en la app que "no available server") - $health['checks']['database'] = [ - 'status' => 'warning', - 'error' => $e->getMessage() - ]; -} - -// 3. Check Redis -try { - $redis = new Predis\Client([ - 'scheme' => getenv('REDIS_SCHEME') ?: 'tcp', - 'host' => getenv('REDIS_HOST') ?: 'redis', - 'port' => getenv('REDIS_PORT') ?: 6379, - ]); - - $ping = $redis->ping(); - - $health['checks']['redis'] = [ - 'status' => ((string)$ping === 'PONG' || $ping === true) ? 'ok' : 'warning', - 'host' => getenv('REDIS_HOST') ?: '127.0.0.1' - ]; -} catch (Exception $e) { - // Redis es opcional — no marcar el app como unhealthy si Redis falla - $health['checks']['redis'] = [ - 'status' => 'warning', - 'error' => $e->getMessage() - ]; -} - -// 4. Check logs directory -$health['checks']['logs'] = [ - 'status' => is_writable(__DIR__ . '/logs') ? 'ok' : 'error', - 'writable' => is_writable(__DIR__ . '/logs') -]; - -// 5. Check uploads directory -$health['checks']['uploads'] = [ - 'status' => is_writable(__DIR__ . '/uploads') ? 'ok' : 'error', - 'writable' => is_writable(__DIR__ . '/uploads') -]; - -// 6. Check Queue stats (opcional) -try { - require_once __DIR__ . '/queue/RedisQueue.php'; - $queue = new WhatsApp\Queue\RedisQueue(); - $stats = $queue->getStats(); - - $health['checks']['queue'] = [ - 'status' => 'ok', - 'stats' => $stats - ]; -} catch (Exception $e) { - $health['checks']['queue'] = [ - 'status' => 'warning', - 'error' => $e->getMessage() - ]; -} - -// HTTP status code -http_response_code($health['status'] === 'healthy' ? 200 : 503); - -echo json_encode($health, JSON_PRETTY_PRINT); +http_response_code(200); +echo json_encode(['status' => 'healthy', 'php' => PHP_VERSION, 'ts' => time()]);