From 8c8c0b0b91065140ae60ad255c23a9d62b8a63ec Mon Sep 17 00:00:00 2001 From: isUnknown Date: Mon, 4 May 2026 10:50:12 +0200 Subject: [PATCH] Defensive : timeout shell sur pagedjs-cli + message d'erreur explicite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wrapper `timeout 360` autour de pagedjs-cli pour SIGTERM-er le process si Chrome hang au-delà du protocolTimeout interne. Détecte le code 124 du shell timeout pour donner un message clair à l'utilisateur. Cron de cleanup orphan installé manuellement sur le VPS dans /etc/cron.d/web2print-cleanup (toutes les 15 min, appelle worker.php --cleanup). Co-Authored-By: Claude Sonnet 4.6 --- config/config.php | 1 + src/Services/PdfGenerator.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.php b/config/config.php index feb144d..4f7bc38 100644 --- a/config/config.php +++ b/config/config.php @@ -20,6 +20,7 @@ return [ // Jobs asynchrones 'job_max_age' => 3600, // 1h, age au-delà duquel un job orphelin est supprimé + 'job_max_duration' => 360, // 6 min, kill SIGTERM via `timeout` si pagedjs-cli ne termine pas // Limites 'max_html_size' => 5 * 1024 * 1024, // 5 MB diff --git a/src/Services/PdfGenerator.php b/src/Services/PdfGenerator.php index 34b7c89..7aeea17 100644 --- a/src/Services/PdfGenerator.php +++ b/src/Services/PdfGenerator.php @@ -87,7 +87,12 @@ class PdfGenerator public function generateFromUrlToFile(string $url, string $pdfFile, array $options = []): void { - $cmd = 'TMPDIR=' . escapeshellarg($this->config['tmp_dir']) . ' '; + // Wrap avec `timeout NSEC` : kill SIGTERM si pagedjs-cli ne termine pas dans le délai. + // Garde-fou contre les pages qui bloquent Chrome au-delà du protocolTimeout interne. + $maxDuration = $this->config['job_max_duration'] ?? 360; + + $cmd = 'timeout ' . (int)$maxDuration . ' '; + $cmd .= 'TMPDIR=' . escapeshellarg($this->config['tmp_dir']) . ' '; $cmd .= escapeshellcmd($this->config['pagedjs_bin']); $cmd .= ' ' . escapeshellarg($url); $cmd .= ' -o ' . escapeshellarg($pdfFile); @@ -103,6 +108,12 @@ class PdfGenerator $returnCode = 0; exec($cmd . ' 2>&1', $output, $returnCode); + if ($returnCode === 124) { + $msg = 'Génération interrompue après ' . $maxDuration . 's (timeout shell). La page est probablement trop lourde — réduisez les dimensions des images cover/body.'; + $this->log('Timeout shell: ' . $msg); + throw new \Exception($msg); + } + if ($returnCode !== 0) { $this->log('Paged.js CLI error (job): ' . implode("\n", $output)); throw new \Exception('PDF generation failed: ' . implode("\n", $output));