Skip to content

Commit

Permalink
Minz : bug avec OPcache de PHP 5.5+
Browse files Browse the repository at this point in the history
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é.
  • Loading branch information
Alkarex committed Jan 1, 2014
1 parent 132e188 commit 66229a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
20 changes: 15 additions & 5 deletions app/Models/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class FreshRSS_Configuration extends Minz_ModelArray {
class FreshRSS_Configuration {
private $filename;

private $data = array(
'language' => 'en',
'old_entries' => 3,
Expand Down Expand Up @@ -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])) {
Expand All @@ -75,8 +79,14 @@ public function __construct ($user) {
}

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) {
Expand Down
17 changes: 7 additions & 10 deletions lib/Minz/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,22 @@ public static function writeFile() {
'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
Expand Down
5 changes: 4 additions & 1 deletion lib/Minz/ModelArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ protected function loadArray() {
* 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;
}

Expand Down

2 comments on commit 66229a5

@Alkarex
Copy link
Member Author

@Alkarex Alkarex commented on 66229a5 Jan 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contribue à #126 et #303

@Alkarex
Copy link
Member Author

@Alkarex Alkarex commented on 66229a5 Jan 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Voir changement oublié bc4116e

Please sign in to comment.