-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -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; | ||
} | ||
} |