From a3e089caab7eff1b321ff84c026babe4173b7666 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 21 Feb 2026 10:49:39 -0500 Subject: [PATCH] up --- classes/MediaService.php | 15 +++++++++++---- docker/entrypoint.sh | 8 ++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/classes/MediaService.php b/classes/MediaService.php index bc5cda4..30546ae 100644 --- a/classes/MediaService.php +++ b/classes/MediaService.php @@ -231,11 +231,15 @@ class MediaService { } $tmpFile = tempnam(sys_get_temp_dir(), 'wget_'); + // Solo pasar Authorization header para evitar problemas con User-Agent personalizado en CDN $headerArgs = ''; foreach ($headers as $h) { - $headerArgs .= ' --header=' . escapeshellarg($h); + if (stripos($h, 'Authorization:') === 0) { + $headerArgs .= ' --header=' . escapeshellarg($h); + } } - $cmd = 'wget -q --prefer-family=IPv4 -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1'; + // --tries=5: reintenta automáticamente ante Connection reset by peer (problema con lookaside.fbsbx.com) + $cmd = 'wget --tries=5 --prefer-family=IPv4 -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1'; try { exec($cmd, $output, $exitCode); } catch (\Error $e) { @@ -244,14 +248,17 @@ class MediaService { return $this->procOpenDownload($url, $headers); } - if ($exitCode === 0 && file_exists($tmpFile) && filesize($tmpFile) > 0) { + $fileSize = (file_exists($tmpFile) ? filesize($tmpFile) : 0); + error_log("[MediaService::shellDownload] wget exit={$exitCode} size={$fileSize} output=" . implode(' | ', array_slice($output, -3))); + + if ($exitCode === 0 && $fileSize > 0) { $content = file_get_contents($tmpFile); unlink($tmpFile); error_log("[MediaService::shellDownload] wget OK, " . strlen($content) . " bytes"); return $content; } - error_log("[MediaService::shellDownload] wget FAIL exit={$exitCode}"); + error_log("[MediaService::shellDownload] wget FAIL exit={$exitCode} size={$fileSize}"); if (file_exists($tmpFile)) unlink($tmpFile); return false; } diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index cf057be..b44787b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -119,16 +119,16 @@ fi echo "⏰ Configurando cron jobs..." cat > /etc/crontabs/root <processDelayed('messages'); \$q->processDelayed('media');" 2>&1 | logger -t delayed-processor +* * * * * cd /var/www/html && /usr/local/bin/php -r "require 'vendor/autoload.php'; use WhatsApp\Queue\RedisQueue; \$q = new RedisQueue(); \$q->processDelayed('messages'); \$q->processDelayed('media');" >> /tmp/delayed_processor.log 2>&1 # Procesar cola de media pendiente cada 2 minutos -*/2 * * * * cd /var/www/html && /usr/local/bin/php scripts/media_worker.php 2>&1 | logger -t media-worker +*/2 * * * * cd /var/www/html && /usr/local/bin/php scripts/media_worker.php >> /tmp/media_worker.log 2>&1 # Limpiar logs antiguos (diario a las 3 AM) -0 3 * * * cd /var/www/html && /usr/local/bin/php -r "require 'classes/LoggerFactory.php'; echo LoggerFactory::cleanup(30) . ' logs eliminados';" 2>&1 | logger -t log-cleanup +0 3 * * * cd /var/www/html && /usr/local/bin/php -r "require 'classes/LoggerFactory.php'; echo LoggerFactory::cleanup(30) . ' logs eliminados';" >> /tmp/log_cleanup.log 2>&1 # Health check de workers (cada 5 minutos) -*/5 * * * * supervisorctl status whatsapp-worker:* | grep -q RUNNING || supervisorctl restart whatsapp-worker:* 2>&1 | logger -t worker-monitor +*/5 * * * * supervisorctl status whatsapp-worker:* | grep -q RUNNING || supervisorctl restart whatsapp-worker:* >> /tmp/worker_monitor.log 2>&1 EOF echo "✅ Configuración completada"