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()]);