本文整理汇总了PHP中opcache_invalidate函数的典型用法代码示例。如果您正苦于以下问题:PHP opcache_invalidate函数的具体用法?PHP opcache_invalidate怎么用?PHP opcache_invalidate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了opcache_invalidate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write_cache_file
function write_cache_file($file, $content)
{
// Open
$handle = @fopen($file, 'r+b');
// @ - file may not exist
if (!$handle) {
$handle = fopen($file, 'wb');
if (!$handle) {
return false;
}
}
// Lock
flock($handle, LOCK_EX);
ftruncate($handle, 0);
// Write
if (fwrite($handle, $content) === false) {
// Unlock and close
flock($handle, LOCK_UN);
fclose($handle);
return false;
}
// Unlock and close
flock($handle, LOCK_UN);
fclose($handle);
// Force opcache to recompile this script
if (function_exists('opcache_invalidate')) {
opcache_invalidate($file, true);
}
return true;
}
示例2: write
/**
* {@inheritdoc}
*/
public function write($key, $content)
{
$dir = dirname($key);
if (!is_dir($dir)) {
if (false === @mkdir($dir, 0777, true)) {
clearstatcache(false, $dir);
if (!is_dir($dir)) {
throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
}
}
} elseif (!is_writable($dir)) {
throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
}
$tmpFile = tempnam($dir, basename($key));
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
@chmod($key, 0666 & ~umask());
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
// Compile cached file into bytecode cache
if (function_exists('opcache_invalidate')) {
opcache_invalidate($key, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($key);
}
}
return;
}
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
}
示例3: flush_file
public function flush_file($filename)
{
if (file_exists($filename)) {
} else {
if (file_exists(ABSPATH . $filename)) {
$filename = ABSPATH . DIRECTORY_SEPARATOR . $filename;
} elseif (file_exists(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename)) {
$filename = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename;
} elseif (file_exists(WPINC . DIRECTORY_SEPARATOR . $filename)) {
$filename = WPINC . DIRECTORY_SEPARATOR . $filename;
} elseif (file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename)) {
$filename = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename;
} else {
return false;
}
}
if (function_exists('opcache_invalidate')) {
return opcache_invalidate($filename, true);
} else {
if (function_exists('apc_compile_file')) {
return apc_compile_file($filename);
}
}
return false;
}
示例4: commit
/**
* Writes all configuration to application configuration file
* @return bool result, true if success
*/
public function commit()
{
$data = <<<PHP
<?php
/*
* ! WARNING !
*
* This file is auto-generated.
* Please don't modify it by-hand or all your changes can be lost.
*/
{$this->append}
return
PHP;
$data .= VarDumper::export($this->configuration);
$data .= ";\n\n";
$result = file_put_contents($this->filename, $data, LOCK_EX) !== false;
if ($result) {
if (function_exists('opcache_invalidate')) {
opcache_invalidate($this->filename, true);
}
if (function_exists('apc_delete_file')) {
@apc_delete_file($this->filename);
}
}
return $result;
}
示例5: getAllActive
/**
* Returns all supported and active opcaches
*
* @return array Array filled with supported and active opcaches
*/
public function getAllActive()
{
$xcVersion = phpversion('xcache');
$supportedCaches = array('OPcache' => array('active' => extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1', 'version' => phpversion('Zend OPcache'), 'canReset' => TRUE, 'canInvalidate' => function_exists('opcache_invalidate'), 'error' => FALSE, 'clearCallback' => function ($fileAbsPath) {
if ($fileAbsPath !== NULL && function_exists('opcache_invalidate')) {
opcache_invalidate($fileAbsPath);
} else {
opcache_reset();
}
}), 'WinCache' => array('active' => extension_loaded('wincache') && ini_get('wincache.ocenabled') === '1', 'version' => phpversion('wincache'), 'canReset' => TRUE, 'canInvalidate' => TRUE, 'error' => FALSE, 'clearCallback' => function ($fileAbsPath) {
if ($fileAbsPath !== NULL) {
wincache_refresh_if_changed(array($fileAbsPath));
} else {
// No argument means refreshing all.
wincache_refresh_if_changed();
}
}), 'XCache' => array('active' => extension_loaded('xcache'), 'version' => $xcVersion, 'canReset' => !ini_get('xcache.admin.enable_auth'), 'canInvalidate' => FALSE, 'error' => FALSE, 'clearCallback' => function ($fileAbsPath) {
if (!ini_get('xcache.admin.enable_auth')) {
xcache_clear_cache(XC_TYPE_PHP);
}
}));
$activeCaches = array();
foreach ($supportedCaches as $opcodeCache => $properties) {
if ($properties['active']) {
$activeCaches[$opcodeCache] = $properties;
}
}
return $activeCaches;
}
示例6: invalidate
function invalidate($file)
{
// Invalidates a specific cached script. The script will be parsed again on the next visit.
// Be sure to include the full location to the file; typically you will use BASEPATH to point
// to the desired file -- e.g., BASEPATH.'public/views/example/example.php'
return opcache_invalidate($file, true);
}
示例7: save
/**
* Formats the output and saved it to disc.
*
* @param string $identifier filename
* @param $contents $contents language array to save
* @return bool \File::update result
*/
public function save($identifier, $contents)
{
// store the current filename
$file = $this->file;
// save it
$return = parent::save($identifier, $contents);
// existing file? saved? and do we need to flush the opcode cache?
if ($file == $this->file and $return and static::$flush_needed) {
if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
// locate the file
if ($pos = strripos($identifier, '::')) {
// get the namespace path
if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
// strip the namespace from the filename
$identifier = substr($identifier, $pos + 2);
// strip the classes directory as we need the module root
$file = substr($file, 0, -8) . 'lang' . DS . $identifier;
} else {
// invalid namespace requested
return false;
}
} else {
$file = \Finder::search('lang', $identifier);
}
}
// make sure we have a fallback
$file or $file = APPPATH . 'lang' . DS . $identifier;
// flush the opcode caches that are active
static::$uses_opcache and opcache_invalidate($file, true);
static::$uses_apc and apc_compile_file($file);
}
return $return;
}
示例8: saveAction
/**
* @Request({"config": "array", "option": "array", "tab": "int"}, csrf=true)
*/
public function saveAction($data, $option, $tab = 0)
{
// TODO: validate
$data['app.debug'] = @$data['app.debug'] ?: '0';
$data['profiler.enabled'] = @$data['profiler.enabled'] ?: '0';
$data['app.nocache'] = @$data['app.nocache'] ?: '0';
$data['cache.cache.storage'] = @$data['cache.cache.storage'] ?: 'auto';
$option['system:app.site_title'] = @$option['system:app.site_title'] ?: '';
$option['system:maintenance.enabled'] = @$option['system:maintenance.enabled'] ?: '0';
foreach ($data as $key => $value) {
$this->config->set($key, $value);
}
file_put_contents($this->configFile, $this->config->dump());
foreach ($option as $key => $value) {
$this['option']->set($key, $value, true);
}
if ($data['cache.cache.storage'] != $this['config']->get('cache.cache.storage') || $data['app.debug'] != $this['config']->get('app.debug')) {
$this['system']->clearCache();
}
if (function_exists('opcache_invalidate')) {
opcache_invalidate($this->configFile);
}
$this['message']->success(__('Settings saved.'));
return $this->redirect('@system/settings', compact('tab'));
}
示例9: initialize
/**
* Initialize the ClearCache-Callbacks
*
* @return void
*/
protected static function initialize()
{
self::$clearCacheCallbacks = array();
// Zend OpCache (built in by default since PHP 5.5) - http://php.net/manual/de/book.opcache.php
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1') {
self::$clearCacheCallbacks[] = function ($absolutePathAndFilename) {
if ($absolutePathAndFilename !== null && function_exists('opcache_invalidate')) {
opcache_invalidate($absolutePathAndFilename);
} else {
opcache_reset();
}
};
}
// WinCache - http://www.php.net/manual/de/book.wincache.php
if (extension_loaded('wincache') && ini_get('wincache.ocenabled') === '1') {
self::$clearCacheCallbacks[] = function ($absolutePathAndFilename) {
if ($absolutePathAndFilename !== null) {
wincache_refresh_if_changed(array($absolutePathAndFilename));
} else {
// Refresh everything!
wincache_refresh_if_changed();
}
};
}
// XCache - http://xcache.lighttpd.net/
// Supported in version >= 3.0.1
if (extension_loaded('xcache')) {
self::$clearCacheCallbacks[] = function ($absolutePathAndFilename) {
// XCache can only be fully cleared.
if (!ini_get('xcache.admin.enable_auth')) {
xcache_clear_cache(XC_TYPE_PHP);
}
};
}
}
示例10: setParams
public function setParams($params)
{
file_put_contents($file = $this->getParamsFile(), '<?php return ' . var_export($params, true) . ';');
if (function_exists('opcache_invalidate')) {
opcache_invalidate($file);
}
}
示例11: loadFile
/**
* @return void
*/
private function loadFile($class, $generator)
{
$file = "{$this->tempDirectory}/{$class}.php";
if (!$this->isExpired($file) && @(include $file) !== FALSE) {
// @ file may not exist
return;
}
if (!is_dir($this->tempDirectory)) {
@mkdir($this->tempDirectory);
// @ - directory may already exist
}
$handle = fopen("{$file}.lock", 'c+');
if (!$handle || !flock($handle, LOCK_EX)) {
throw new Nette\IOException("Unable to acquire exclusive lock on '{$file}.lock'.");
}
if (!is_file($file) || $this->isExpired($file)) {
list($toWrite[$file], $toWrite["{$file}.meta"]) = $this->generate($class, $generator);
foreach ($toWrite as $name => $content) {
if (file_put_contents("{$name}.tmp", $content) !== strlen($content) || !rename("{$name}.tmp", $name)) {
@unlink("{$name}.tmp");
// @ - file may not exist
throw new Nette\IOException("Unable to create file '{$name}'.");
} elseif (function_exists('opcache_invalidate')) {
@opcache_invalidate($name, TRUE);
// @ can be restricted
}
}
}
if (@(include $file) === FALSE) {
// @ - error escalated to exception
throw new Nette\IOException("Unable to include '{$file}'.");
}
flock($handle, LOCK_UN);
}
示例12: script_put_contents
/**
* Identical than file_put_contents, but must be used instead for PHP files in order to invalidate
* PHP caching
*
* @param $filename string
* @param $data string
*/
function script_put_contents($filename, $data)
{
if (file_put_contents($filename, $data)) {
if (function_exists('opcache_invalidate') && substr($filename, -4) == '.php') {
opcache_invalidate($filename, true);
}
}
}
示例13: invalidate
/**
* Invalidates a PHP file from a possibly active opcode cache.
*
* In case the opcode cache does not support to invalidate an individual file,
* the entire cache will be flushed.
*
* @param string $pathname
* The absolute pathname of the PHP file to invalidate.
*/
public static function invalidate($pathname)
{
clearstatcache(TRUE, $pathname);
// Check if the Zend OPcache is enabled and if so invalidate the file.
if (function_exists('opcache_invalidate')) {
opcache_invalidate($pathname, TRUE);
}
}
示例14: invalidateScript
public static function invalidateScript($path)
{
if (extension_loaded('Zend OPcache')) {
opcache_invalidate($path);
} elseif (extension_loaded('apc')) {
apc_delete_file($path);
}
}
示例15: __cms_config
function __cms_config($key, $value = NULL, $delete = FALSE, $file_name, $config_load_alias)
{
if (!file_exists($file_name)) {
return FALSE;
}
$pattern = array();
$pattern[] = '/(\\$config\\[(\'|")' . $key . '(\'|")\\] *= *")(.*?)(";)/si';
$pattern[] = "/(" . '\\$' . "config\\[('|\")" . $key . "('|\")\\] *= *')(.*?)(';)/si";
if ($delete) {
$replacement = '';
$str = file_get_contents($file_name);
$str = preg_replace($pattern, $replacement, $str);
@chmod($file_name, 0777);
if (strpos($str, '<?php') !== FALSE && strpos($str, '$config') !== FALSE) {
@file_put_contents($file_name, $str);
@chmod($file_name, 0555);
}
return FALSE;
} else {
if ($value === NULL) {
// enforce refresh
if (function_exists('opcache_invalidate')) {
opcache_invalidate($file_name);
}
include $file_name;
if (!isset($config)) {
$config = array();
}
if (key_exists($key, $config)) {
$value = $config[$key];
} else {
$value = '';
}
return $value;
} else {
$str = file_get_contents($file_name);
$replacement = '${1}' . addslashes($value) . '${5}';
$found = FALSE;
foreach ($pattern as $single_pattern) {
if (preg_match($single_pattern, $str)) {
$found = TRUE;
break;
}
}
if (!$found) {
$str .= PHP_EOL . '$config[\'' . $key . '\'] = \'' . addslashes($value) . '\';';
} else {
$str = preg_replace($pattern, $replacement, $str);
}
@chmod($file_name, 0777);
if (strpos($str, '<?php') !== FALSE && strpos($str, '$config') !== FALSE) {
@file_put_contents($file_name, $str, LOCK_EX);
@chmod($file_name, 0555);
}
return $value;
}
}
}