소스 검색

add function to invalidate one opcache file, use it if possible #9885

Issue #9885 appears to be triggered by ownCloud invalidating the entire
PHP opcache. Testing indicates it can be avoided by only invalidating the
single file that was written from the opcache, instead of clearing the
whole thing. In general it is more efficient to invalidate only the single
file that was changed, rather than the whole cache.

This adds a deleteFromOpcodeCache() function which invalidates a single
file from the opcache if possible, returning true if the underlying
function returns true (which may mean 'success', or 'file does not exist',
or 'file exists but is not in opcache', all of which are OK to treat as
good for our purposes). It also changes writeData() in config.php to try
using deleteFromOpcodeCache() and only fall back on clearOpcodeCache() if
that fails.
tags/v8.1.0alpha1
Adam Williamson 9 년 전
부모
커밋
3b4823d89c
2개의 변경된 파일30개의 추가작업 그리고 2개의 파일을 삭제
  1. 5
    2
      lib/private/config.php
  2. 25
    0
      lib/private/util.php

+ 5
- 2
lib/private/config.php 파일 보기

@@ -207,8 +207,11 @@ class Config {
flock($filePointer, LOCK_UN);
fclose($filePointer);

// Clear the opcode cache
\OC_Util::clearOpcodeCache();
// Try invalidating the opcache just for the file we wrote...
if (!\OC_Util::deleteFromOpcodeCache($this->configFilename)) {
// But if that doesn't work, clear the whole cache.
\OC_Util::clearOpcodeCache();
}
}
}


+ 25
- 0
lib/private/util.php 파일 보기

@@ -1249,6 +1249,31 @@ 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
*
* @return bool true if underlying function returns true, otherwise false
*/
public static function deleteFromOpcodeCache($path=NULL) {
$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

Loading…
취소
저장