Explorar o código

Merge pull request #1679 from PrivateBin/opcache

Make OPcache optional
El RIDO hai 9 meses
pai
achega
5c5fe333a0
Modificáronse 2 ficheiros con 14 adicións e 16 borrados
  1. 1 1
      doc/Installation.md
  2. 13 15
      lib/Data/Filesystem.php

+ 1 - 1
doc/Installation.md

@@ -30,7 +30,7 @@ for more information.
 ### Optional Requirements
 
 - PHP with GD extension (when using identicon or vizhash icons, jdenticon works
-  without it)
+  without it) and OPcache (for better performance)
 - a database supported by [PHP PDO](https://php.net/manual/book.pdo.php) and the
   PHP PDO extension (when using database storage)
 - a Ceph cluster with Rados gateway or AWS S3 storage (when using S3 storage)

+ 13 - 15
lib/Data/Filesystem.php

@@ -267,27 +267,25 @@ class Filesystem extends AbstractData
      */
     public function setValue($value, $namespace, $key = '')
     {
+        $file = $this->_path . DIRECTORY_SEPARATOR . $namespace . '.php';
+        if (function_exists('opcache_invalidate')) {
+            opcache_invalidate($file);
+        }
         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) . ';'
-                );
+                $content = '<?php' . PHP_EOL . '$GLOBALS[\'purge_limiter\'] = ' . var_export($value, true) . ';';
+                break;
             case 'salt':
-                return $this->_storeString(
-                    $this->_path . DIRECTORY_SEPARATOR . 'salt.php',
-                    '<?php # |' . $value . '|'
-                );
+                $content = '<?php # |' . $value . '|';
+                break;
             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) . ';'
-                );
+                $content                 = '<?php' . PHP_EOL . '$GLOBALS[\'traffic_limiter\'] = ' . var_export($this->_last_cache, true) . ';';
+                break;
+            default:
+                return false;
         }
-        return false;
+        return $this->_storeString($file, $content);
     }
 
     /**