diff --git a/lib/private/Config.php b/lib/private/Config.php index 0e3a9b22a7710..f10393ce871b9 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -59,6 +59,8 @@ class Config { protected $configFileName; /** @var bool */ protected $isReadOnly; + /** @var int */ + protected $lastChecksum; /** * @param string $configDir Path to the config dir, needs to end with '/' @@ -258,10 +260,23 @@ private function writeData() { throw new HintException(sprintf('Configuration was not read or initialized correctly, not overwriting %s', $this->configFilePath)); } + // This creates a checksum of the config file in memory. + // The config file opcache code is only invalidated if the + // config file data has been changed therefore all the other + // code that depend on the the config file opcode will not + // be recompiled. + $data = var_export($this->cache, true); + $currentChecksum = crc32($data); + + if ($this->getLastChecksum() == $currentChecksum) + return; + + $this->lastChecksum = $currentChecksum; + // Create a php file ... $content = "cache, true); + $content .= $data; $content .= ";\n"; touch($this->configFilePath); @@ -304,4 +319,16 @@ private function checkReadOnly(): void { 'Unset "config_is_read_only" to allow changes to the config file.'); } } + + private function getLastChecksum(): int { + if ($this->lastChecksum == null) { + if (file_exists($this->configFilePath)) { + $data = file_get_contents($this->configFilePath); + $this->lastChecksum = crc32($data); + } else { + $this->lastChecksum = 0; + } + } + return $this->lastChecksum; + } }