From 88bb079d45ed2a7beb6a90255206647295ca579a Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 29 Jul 2025 17:36:18 +0200 Subject: [PATCH] functions.php: tweak compressed page creation --- inc/functions.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index c9f6657e..e6ce4bb2 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -647,13 +647,14 @@ function file_write($path, $data, $simple = false, $skip_purge = false) { if ($config['gzip_static']) { $gzpath = "$path.gz"; - if ($bytes & ~0x3ff) { // if ($bytes >= 1024) - if (file_put_contents($gzpath, gzencode($data), $simple ? 0 : LOCK_EX) === false) - error("Unable to write to file: $gzpath"); - //if (!touch($gzpath, filemtime($path), fileatime($path))) - // error("Unable to touch file: $gzpath"); - } - else { + // 12KBs (2 left for headers etc) to stay within the 14 KBs of the standard initial TCP packet. + if ($bytes >= 12288) { + if (\file_put_contents($gzpath, \gzencode($data), $simple ? 0 : LOCK_EX) === false) { + // Do not fail completely if the write fails. + \error_log("Unable to write to file: $gzpath"); + @unlink($gzpath); + } + } else { @unlink($gzpath); } }