Просмотр исходного кода

ensure PHP opcache gets invalidated, when storing data in file parsed via PHP require

El RIDO 9 месяцев назад
Родитель
Сommit
ad983ef670
2 измененных файлов с 6 добавлено и 10 удалено
  1. 2 0
      lib/Data/Filesystem.php
  2. 4 10
      lib/Persistence/TrafficLimiter.php

+ 2 - 0
lib/Data/Filesystem.php

@@ -274,6 +274,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',
                     '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . var_export($value, true) . ';'
@@ -285,6 +286,7 @@ class Filesystem extends AbstractData
                 );
             case 'traffic_limiter':
                 $this->_last_cache[$key] = $value;
+                opcache_invalidate($this->_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php');
                 return $this->_storeString(
                     $this->_path . DIRECTORY_SEPARATOR . 'traffic_limiter.php',
                     '<?php' . PHP_EOL . '$GLOBALS[\'traffic_limiter\'] = ' . var_export($this->_last_cache, true) . ';'

+ 4 - 10
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::_(