Merge pull request #11056 from AdamWill/9885-opcode

add function to invalidate one opcache file, use it if possible #9885
This commit is contained in:
Morris Jobke 2015-02-10 17:21:15 +01:00
commit 11283c57d9
2 changed files with 31 additions and 2 deletions

View file

@ -236,8 +236,11 @@ class Config {
flock($filePointer, LOCK_UN);
fclose($filePointer);
// Clear the opcode cache
// Try invalidating the opcache just for the file we wrote...
if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) {
// But if that doesn't work, clear the whole cache.
\OC_Util::clearOpcodeCache();
}
}
}

View file

@ -1271,6 +1271,32 @@ class OC_Util {
return $theme;
}
/**
* Clear a single file from the opcode cache
* This is useful for writing to the config file
* in case the opcode cache does not re-validate files
* Returns true if successful, false if unsuccessful:
* caller should fall back on clearing the entire cache
* with clearOpcodeCache() if unsuccessful
*
* @param string $path the path of the file to clear from the cache
* @return bool true if underlying function returns true, otherwise false
*/
public static function deleteFromOpcodeCache($path) {
$ret = false;
if ($path) {
// APC >= 3.1.1
if (function_exists('apc_delete_file')) {
$ret = @apc_delete_file($path);
}
// Zend OpCache >= 7.0.0, PHP >= 5.5.0
if (function_exists('opcache_invalidate')) {
$ret = opcache_invalidate($path);
}
}
return $ret;
}
/**
* Clear the opcode cache if one exists
* This is necessary for writing to the config file