From 6054e99849608b2ca1de9a1a0fc799e4c53a6b1b Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 12 Oct 2025 11:39:58 +0200 Subject: [PATCH] ensure PHP opcache gets invalidated, when storing data in file parsed via PHP require --- CHANGELOG.md | 1 + lib/Data/Filesystem.php | 2 ++ lib/Persistence/TrafficLimiter.php | 14 ++++---------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 903595b0..7683a081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * FIXED: Allow pasting a password for decrypting a paste (#1620) * FIXED: Allow copying the shortened link after using a URL shortener (#1624) * FIXED: URL extraction fails when frame-ancestors is set in CSP (#1644) +* FIXED: traffic limiter not working when using Filesystem storage and PHP opcache ## 2.0.0 (2025-07-28) * ADDED: Error logging in database and filesystem backend (#1554) diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index 0e5f9edd..b6837e26 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -269,6 +269,7 @@ class Filesystem extends AbstractData { switch ($namespace) { case 'purge_limiter': + opcache_invalidate($this->_path . DIRECTORY_SEPARATOR . 'purge_limiter.php'); return $this->_storeString( $this->_path . DIRECTORY_SEPARATOR . 'purge_limiter.php', '_last_cache[$key] = $value; + opcache_invalidate($this->_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php'); return $this->_storeString( $this->_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php', '_last_cache, true) . ';' diff --git a/lib/Persistence/TrafficLimiter.php b/lib/Persistence/TrafficLimiter.php index 5f120019..60977f5d 100644 --- a/lib/Persistence/TrafficLimiter.php +++ b/lib/Persistence/TrafficLimiter.php @@ -204,16 +204,10 @@ class TrafficLimiter extends AbstractPersistence $now = time(); $tl = (int) self::$_store->getValue('traffic_limiter', $hash); self::$_store->purgeValues('traffic_limiter', $now - self::$_limit); - if ($tl > 0 && ($tl + self::$_limit >= $now)) { - $result = false; - } else { - $tl = time(); - $result = true; - } - if (!self::$_store->setValue((string) $tl, 'traffic_limiter', $hash)) { - error_log('failed to store the traffic limiter, it probably contains outdated information'); - } - if ($result) { + if ($tl === 0 || ($tl + self::$_limit) < $now) { + if (!self::$_store->setValue((string) $now, 'traffic_limiter', $hash)) { + error_log('failed to store the traffic limiter, it probably contains outdated information'); + } return true; } throw new Exception(I18n::_(