Skip to content

Commit

Permalink
Fixed bug with opcode caches
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Dec 5, 2013
1 parent 11dee60 commit fd1bda4
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/MadeYourDay/Contao/CustomElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Provide miscellaneous methods that are used by the data configuration arrays.
*
* @author Martin Auswöger <[email protected]>
* @todo Create cache files with different names to be able to drop the
* refreshOpcodeCache method
*/
class CustomElements extends \Backend
{
Expand Down Expand Up @@ -657,6 +659,7 @@ public static function purgeCache()
$file = new \File($filePath, true);
$file->write('');
$file->close();
static::refreshOpcodeCache($fileFullPath);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

0 comments on commit fd1bda4

Please sign in to comment.