当前位置: 首页>>代码示例>>PHP>>正文


PHP opcache_invalidate函数代码示例

本文整理汇总了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;
}
开发者ID:mdb-webdev,项目名称:punbb,代码行数:30,代码来源:cache.php

示例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));
 }
开发者ID:kayneth,项目名称:site_enchere,代码行数:31,代码来源:Filesystem.php

示例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;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:25,代码来源:SystemOpCache_Core.php

示例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;
    }
开发者ID:DevGroup-ru,项目名称:yii2-extensions-manager,代码行数:30,代码来源:ApplicationConfigWriter.php

示例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;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:34,代码来源:OpcodeCacheService.php

示例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);
 }
开发者ID:arout,项目名称:halcyon,代码行数:7,代码来源:Opcache.php

示例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;
 }
开发者ID:takawasitobi,项目名称:pembit,代码行数:40,代码来源:php.php

示例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'));
 }
开发者ID:amirkheirabadi,项目名称:pagekit,代码行数:28,代码来源:SettingsController.php

示例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);
             }
         };
     }
 }
开发者ID:kszyma,项目名称:flow-development-collection,代码行数:40,代码来源:OpcodeCacheHelper.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);
     }
 }
开发者ID:sebcode,项目名称:gsandbox,代码行数:7,代码来源:VaultEntity.php

示例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);
 }
开发者ID:nette,项目名称:di,代码行数:37,代码来源:ContainerLoader.php

示例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);
        }
    }
}
开发者ID:TuxBoy,项目名称:Demo-saf,代码行数:15,代码来源:file_functions.php

示例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);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:OpCodeCache.php

示例14: invalidateScript

 public static function invalidateScript($path)
 {
     if (extension_loaded('Zend OPcache')) {
         opcache_invalidate($path);
     } elseif (extension_loaded('apc')) {
         apc_delete_file($path);
     }
 }
开发者ID:KnightAR,项目名称:Emergence,代码行数:8,代码来源:Cache.class.php

示例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;
        }
    }
}
开发者ID:jeremywong1992,项目名称:No-CMS,代码行数:58,代码来源:cms_helper.php


注:本文中的opcache_invalidate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。