diff --git a/src/MadeYourDay/Contao/CustomElements.php b/src/MadeYourDay/Contao/CustomElements.php index 1c00484..5a02179 100644 --- a/src/MadeYourDay/Contao/CustomElements.php +++ b/src/MadeYourDay/Contao/CustomElements.php @@ -16,6 +16,8 @@ * Provide miscellaneous methods that are used by the data configuration arrays. * * @author Martin Auswöger + * @todo Create cache files with different names to be able to drop the + * refreshOpcodeCache method */ class CustomElements extends \Backend { @@ -657,6 +659,7 @@ public static function purgeCache() $file = new \File($filePath, true); $file->write(''); $file->close(); + static::refreshOpcodeCache($fileFullPath); } } @@ -759,6 +762,7 @@ public static function loadConfig() $file = new \File($filePath, true); $file->write(implode("\n", $contents)); $file->close(); + static::refreshOpcodeCache($fileFullPath); if (file_exists($fileFullPath)) { include $fileFullPath; @@ -781,4 +785,56 @@ public static function reloadConfig() return static::loadConfig(); } + + /** + * Refreshes all active opcode caches for the specified file + * + * @param string $path Path to the file + * @return boolean True on success, false on failure + */ + protected static function refreshOpcodeCache($path) + { + try { + + // Zend OPcache + if (function_exists('opcache_invalidate')) { + opcache_invalidate($path, true); + } + + // Zend Optimizer+ + if (function_exists('accelerator_reset')) { + accelerator_reset(); + } + + // APC + if (function_exists('apc_compile_file') && !ini_get('apc.stat')) { + apc_compile_file($path); + } + + // eAccelerator + if (function_exists('eaccelerator_purge') && !ini_get('eaccelerator.check_mtime')) { + @eaccelerator_purge(); + } + + // XCache + if (function_exists('xcache_count') && !ini_get('xcache.stat')) { + if (($count = xcache_count(XC_TYPE_PHP)) > 0) { + for ($id = 0; $id < $count; $id++) { + xcache_clear_cache(XC_TYPE_PHP, $id); + } + } + } + + // WinCache + if (function_exists('wincache_refresh_if_changed')) { + wincache_refresh_if_changed(array($path)); + } + + } + catch(\Exception $exception) { + return false; + } + + return true; + } }