diff options
| author | 2014-01-01 04:39:39 +0100 | |
|---|---|---|
| committer | 2014-01-01 04:39:39 +0100 | |
| commit | 66229a5d71b85c0a57d63fa8b1cc6e5729cabfe4 (patch) | |
| tree | 9fb232b0ccc70aaa2861e920e78c9ac13164528c | |
| parent | 132e1883e4682ae8f873bbeb420f81f51a4e274f (diff) | |
Minz : bug avec OPcache de PHP 5.5+
Minz ne prenait pas en charge OPcache (cache PHP) http://php.net/opcache
activé par défaut depuis PHP5.5.
Ce fut un peu dur d'isoler ce bug :-/
Il faut penser à appeler opcache_invalidate avant de ré-utiliser un
fichier par include().
Aussi, le mécanisme de lock() n'est plus approprié ni nécessaire.
Pour FreshRSS, évite l'utilisation de ModelArray car il ne restait que
quelques lignes d'utiles, et évite un héritage + appel de classe, ce qui
est toujours ça de gagné.
| -rw-r--r-- | app/Models/Configuration.php | 20 | ||||
| -rw-r--r-- | lib/Minz/Configuration.php | 17 | ||||
| -rw-r--r-- | lib/Minz/ModelArray.php | 5 |
3 files changed, 26 insertions, 16 deletions
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index ec7daaa7d..abd874f27 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -1,6 +1,8 @@ <?php -class FreshRSS_Configuration extends Minz_ModelArray { +class FreshRSS_Configuration { + private $filename; + private $data = array( 'language' => 'en', 'old_entries' => 3, @@ -60,10 +62,12 @@ class FreshRSS_Configuration extends Minz_ModelArray { ); public function __construct ($user) { - $filename = DATA_PATH . '/' . $user . '_user.php'; + $this->filename = DATA_PATH . '/' . $user . '_user.php'; - parent::__construct($filename); - $data = parent::loadArray(); + $data = include($this->filename); + if (!is_array($data)) { + throw new Minz_PermissionDeniedException($this->filename); + } foreach ($data as $key => $value) { if (isset($this->data[$key])) { @@ -75,8 +79,14 @@ class FreshRSS_Configuration extends Minz_ModelArray { } public function save() { + if (file_put_contents($this->filename, "<?php\n return " . var_export($array, true) . ';', LOCK_EX) === false) { + throw new Minz_PermissionDeniedException($this->filename); + } + if (function_exists('opcache_invalidate')) { + opcache_invalidate($this->filename); //Clear PHP 5.5+ cache for include + } invalidateHttpCache(); - return parent::writeArray($this->data); + return true; } public function __get($name) { diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 873908ce6..fc94d9731 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -157,25 +157,22 @@ class Minz_Configuration { 'db' => self::$db, ); @rename(DATA_PATH . self::CONF_PATH_NAME, DATA_PATH . self::CONF_PATH_NAME . '.bak'); - return file_put_contents(DATA_PATH . self::CONF_PATH_NAME, "<?php\n return " . var_export($ini_array, true) . ';'); + $result = file_put_contents(DATA_PATH . self::CONF_PATH_NAME, "<?php\n return " . var_export($ini_array, true) . ';'); + if (function_exists('opcache_invalidate')) { + opcache_invalidate(DATA_PATH . self::CONF_PATH_NAME); //Clear PHP 5.5+ cache for include + } + return (bool)$result; } /** * Parse un fichier de configuration - * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas + * @exception Minz_PermissionDeniedException si le CONF_PATH_NAME n'est pas accessible * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté */ private static function parseFile () { - if (!file_exists (DATA_PATH . self::CONF_PATH_NAME)) { - throw new Minz_FileNotExistException ( - DATA_PATH . self::CONF_PATH_NAME, - Minz_Exception::ERROR - ); - } - $ini_array = include(DATA_PATH . self::CONF_PATH_NAME); - if (!$ini_array) { + if (!is_array($ini_array)) { throw new Minz_PermissionDeniedException ( DATA_PATH . self::CONF_PATH_NAME, Minz_Exception::ERROR diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php index e3ec77dc9..ff23dbc83 100644 --- a/lib/Minz/ModelArray.php +++ b/lib/Minz/ModelArray.php @@ -45,9 +45,12 @@ class Minz_ModelArray { * Sauve le tableau $array dans le fichier $filename **/ protected function writeArray($array) { - if (!file_put_contents($this->filename, "<?php\n return " . var_export($array, true) . ';', LOCK_EX)) { + if (file_put_contents($this->filename, "<?php\n return " . var_export($array, true) . ';', LOCK_EX) === false) { throw new Minz_PermissionDeniedException($this->filename); } + if (function_exists('opcache_invalidate')) { + opcache_invalidate($this->filename); //Clear PHP 5.5+ cache for include + } return true; } |
