Immediately invalidate PHP scripts from opcache if modified or deleted

This commit is contained in:
Kijin Sung 2016-01-09 21:04:51 +09:00
parent d300db933e
commit 8d6068ab2b
2 changed files with 14 additions and 9 deletions

View file

@ -78,10 +78,6 @@ class CacheFile extends CacheBase
$content[] = 'if(!defined(\'__XE__\')) { exit(); }';
$content[] = 'return \'' . addslashes(serialize($obj)) . '\';';
FileHandler::writeFile($cache_file, implode(PHP_EOL, $content));
if(function_exists('opcache_invalidate'))
{
@opcache_invalidate($cache_file, true);
}
}
/**
@ -145,10 +141,6 @@ class CacheFile extends CacheBase
function _delete($_key)
{
$cache_file = $this->getCacheFileName($_key);
if(function_exists('opcache_invalidate'))
{
@opcache_invalidate($cache_file, true);
}
FileHandler::removeFile($cache_file);
}

View file

@ -156,6 +156,10 @@ class FileHandler
@file_put_contents($filename, $buff, $flags|LOCK_EX);
@chmod($filename, 0644);
if(function_exists('opcache_invalidate') && substr($filename, -4) === '.php')
{
@opcache_invalidate($filename, true);
}
}
/**
@ -166,7 +170,16 @@ class FileHandler
*/
public static function removeFile($filename)
{
return (($filename = self::exists($filename)) !== FALSE) && @unlink($filename);
if(($filename = self::exists($filename)) === false)
{
return false;
}
$status = @unlink($filename);
if(function_exists('opcache_invalidate') && substr($filename, -4) === '.php')
{
@opcache_invalidate($filename, true);
}
return $status;
}
/**