Ejemplo n.º 1
0
 public function compileScripts()
 {
     if (!extension_loaded('apc')) {
         return;
     }
     $files = array();
     foreach ($this->_refresh_rules as $rules) {
         $rules = (object) $rules;
         $files = array_merge($files, File::getFilesFromDirectory($rules->dir, $rules->extension, $rules->recursive));
     }
     foreach ($files as $file) {
         if (!$this->isFileCached($file)) {
             if ($d = \apc_delete_file($file)) {
                 Logger::debug('Elimino dalla cache lo script ' . $file . ' per ricompilarlo', RENDER_CORE_LOGNAME);
             } else {
                 Logger::debug('Non sono riuscito ad eliminare ' . $file . ' ' . print_r($d, true));
             }
             if ($d = \apc_compile_file($file)) {
                 Logger::debug('Ho compilato lo script ' . $file, 'core');
             } else {
                 Logger::debug('Non sono riuscito a compilare ' . $file . ' ' . print_r($d, true), 'core');
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function deleteFile($file)
 {
     if (CACHE_STATUS) {
         apc_delete_file($file);
     }
     return false;
 }
Ejemplo n.º 3
0
 public function deleteFile($file)
 {
     if (_cacheStatus) {
         apc_delete_file($file);
     }
     return FALSE;
 }
    /**
     * 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;
    }
Ejemplo n.º 5
0
 public static function invalidateScript($path)
 {
     if (extension_loaded('Zend OPcache')) {
         opcache_invalidate($path);
     } elseif (extension_loaded('apc')) {
         apc_delete_file($path);
     }
 }
Ejemplo n.º 6
0
 /**
  * Invalidates precompiled script cache (such as OPCache or APC) for the given file.
  * @param string $fileName file name.
  * @since 1.0.2
  */
 protected function invalidateScriptCache($fileName)
 {
     if (function_exists('opcache_invalidate')) {
         opcache_invalidate($fileName, true);
     }
     if (function_exists('apc_delete_file')) {
         @apc_delete_file($fileName);
     }
 }
Ejemplo n.º 7
0
 protected function flushConfigCache()
 {
     if (extension_loaded('apc')) {
         if (function_exists('apc_delete_file')) {
             @apc_delete_file(Curry_Core::$config->curry->configPath);
         } else {
             @apc_clear_cache();
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Initialize the cache properties
  */
 protected static function initialize()
 {
     $apcVersion = phpversion('apc');
     $xcVersion = phpversion('xcache');
     static::$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();
         }
     }), 'APC' => array('active' => extension_loaded('apc') && !extension_loaded('apcu') && ini_get('apc.enabled') === '1', 'version' => $apcVersion, 'canReset' => TRUE, 'canInvalidate' => self::canApcInvalidate(), 'error' => $apcVersion && VersionNumberUtility::convertVersionNumberToInteger($apcVersion) < 3001007, 'clearCallback' => function ($fileAbsPath) {
         if ($fileAbsPath !== NULL && OpcodeCacheUtility::getCanInvalidate('APC')) {
             // This may output a warning like: PHP Warning: apc_delete_file(): Could not stat file
             // This warning isn't true, this means that apc was unable to generate the cache key
             // which depends on the configuration of APC.
             apc_delete_file($fileAbsPath);
         } else {
             apc_clear_cache('opcode');
         }
     }), 'WinCache' => array('active' => extension_loaded('wincache') && ini_get('wincache.ocenabled') === '1', 'version' => phpversion('wincache'), 'canReset' => FALSE, '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' => TRUE, 'canInvalidate' => FALSE, 'error' => FALSE, 'clearCallback' => $xcVersion && VersionNumberUtility::convertVersionNumberToInteger($xcVersion) < 3000000 ? function ($fileAbsPath) {
         if (!ini_get('xcache.admin.enable_auth')) {
             xcache_clear_cache(XC_TYPE_PHP, 0);
         }
     } : function ($fileAbsPath) {
         if (!ini_get('xcache.admin.enable_auth')) {
             xcache_clear_cache(XC_TYPE_PHP);
         }
     }), 'eAccelerator' => array('active' => extension_loaded('eAccelerator'), 'version' => phpversion('eaccelerator'), 'canReset' => FALSE, 'canInvalidate' => FALSE, 'error' => TRUE, 'clearCallback' => function ($fileAbsPath) {
         eaccelerator_clear();
     }), 'ZendOptimizerPlus' => array('active' => extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable') === '1', 'version' => phpversion('Zend Optimizer+'), 'canReset' => TRUE, 'canInvalidate' => FALSE, 'error' => FALSE, 'clearCallback' => function ($fileAbsPath) {
         accelerator_reset();
     }));
     static::$activeCaches = array();
     // Cache the active ones
     foreach (static::$supportedCaches as $opcodeCache => $properties) {
         if ($properties['active']) {
             static::$activeCaches[$opcodeCache] = $properties;
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * 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);
     if (extension_loaded('Zend OPcache')) {
         opcache_invalidate($pathname, TRUE);
     }
     // If apcu extension is enabled in PHP 5.5 or greater it emulates apc.
     // This is to provide an easy upgrade path if you are using apc's user
     // caching however the emulation does not extend to opcode caching.
     // Therefore we need to check if the function exists as well.
     if (extension_loaded('apc') && function_exists('apc_delete_file')) {
         // apc_delete_file() throws a PHP warning in case the specified file was
         // not compiled yet.
         // @see http://php.net/manual/en/function.apc-delete-file.php
         @apc_delete_file($pathname);
     }
 }
Ejemplo n.º 10
0
 public function actionClearOutdated()
 {
     $cache = apc_cache_info('opcode');
     $files = array();
     foreach ($cache['cache_list'] as $file) {
         if (filemtime($file['filename']) > $file['mtime']) {
             $files[] = $file['filename'];
         }
     }
     $result = apc_delete_file($files);
     if (empty($result)) {
         Yii::app()->user->setFlash('success', count($files) . ' outdated cache files cleared.');
     } else {
         Yii::app()->user->setFlash('error', 'Puriging the following files from the cache has failed: ' . implode(', ', $result));
     }
     $this->redirect(array('index', '#' => 'fileCache'));
 }
Ejemplo n.º 11
0
 /**
  * Initialize the cache properties
  *
  * @return void
  */
 protected static function initialize()
 {
     $apcVersion = phpversion('apc');
     $xcVersion = phpversion('xcache');
     static::$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, true);
         } else {
             opcache_reset();
         }
     }), 'APC' => array('active' => extension_loaded('apc') && !extension_loaded('apcu') && ini_get('apc.enabled') === '1', 'version' => $apcVersion, 'canReset' => true, 'canInvalidate' => self::canApcInvalidate(), 'error' => $apcVersion && version_compare($apcVersion, '3.1.7', '<'), 'clearCallback' => function ($fileAbsPath) {
         if ($fileAbsPath !== null && iMSCP_Utility_OpcodeCache::getCanInvalidate('APC')) {
             // This may output a warning like: PHP Warning: apc_delete_file(): Could not stat file
             // This warning isn't true, this means that apc was unable to generate the cache key
             // which depends on the configuration of APC.
             @apc_delete_file($fileAbsPath);
         } else {
             apc_clear_cache('opcode');
         }
     }), 'XCache' => array('active' => extension_loaded('xcache'), 'version' => $xcVersion, 'canReset' => true, 'canInvalidate' => false, 'error' => false, 'clearCallback' => $xcVersion && version_compare($xcVersion, '3.0.0', '<') ? function () {
         if (!ini_get('xcache.admin.enable_auth')) {
             xcache_clear_cache(XC_TYPE_PHP, 0);
         }
     } : function () {
         if (!ini_get('xcache.admin.enable_auth')) {
             xcache_clear_cache(XC_TYPE_PHP);
         }
     }), 'eAccelerator' => array('active' => extension_loaded('eAccelerator'), 'version' => phpversion('eaccelerator'), 'canReset' => false, 'canInvalidate' => false, 'error' => false, 'clearCallback' => function () {
         eaccelerator_clear();
     }), 'ZendOptimizerPlus' => array('active' => extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable') === '1', 'version' => phpversion('Zend Optimizer+'), 'canReset' => true, 'canInvalidate' => false, 'error' => false, 'clearCallback' => function () {
         accelerator_reset();
     }));
     static::$activeCaches = array();
     // Cache the active ones
     foreach (static::$supportedCaches as $opcodeCache => $properties) {
         if ($properties['active']) {
             static::$activeCaches[$opcodeCache] = $properties;
         }
     }
 }
Ejemplo n.º 12
0
 protected function clearApc()
 {
     $console = $this->getConsole();
     if (!(bool) ini_get('apc.enable_cli')) {
         $console->writeLine('You must enable APC in CLI before clearing APC cache', Color::RED);
         $console->writeLine('Check the "apc.enable_cli" setting in your php.ini (see http://www.php.net/apc.configuration)');
         return;
     }
     $info = array_keys(apc_cache_info());
     $scripts = $info['cache_list'];
     if (count($scripts) === 0) {
         $console->writeLine('No files cached in APC, aborting', Color::RED);
         return;
     }
     array_map(function ($value) {
         return $value['filename'];
     }, $scripts);
     $results = apc_delete_file($scripts);
     foreach ($results as $result) {
         $console->writeLine('Failed to clear opcode cache for ' . $result, Color::RED);
     }
     $console->writeLine(sprintf('%s APC files cleared', count($scripts)), Color::GREEN);
 }
Ejemplo n.º 13
0
 /** {@inheritdoc} */
 public function showMain()
 {
     if (!is_writable(Curry_Core::$config->curry->configPath)) {
         $this->addMessage("Configuration file doesn't seem to be writable.", self::MSG_ERROR);
     }
     $config = new Zend_Config(require Curry_Core::$config->curry->configPath, true);
     $pages = PagePeer::getSelect();
     $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('enabled' => array('checkbox', array('label' => 'Enable domain mapping', 'value' => $config->curry->domainMapping->enabled)), 'default_base_page' => array('select', array('label' => 'Default base page', 'description' => 'The default base page will only be used if there are no other domains matching and domain mapping is enabled', 'value' => $config->curry->domainMapping->default, 'multiOptions' => array('' => '[ None ]') + $pages)))));
     $domainForm = new Curry_Form_Dynamic(array('legend' => 'Domain', 'elements' => array('domain' => array('text', array('label' => 'Domain', 'description' => 'You can use default as a wildcard to fetch unmatched domains.', 'required' => true)), 'base_page' => array('select', array('label' => 'Base page', 'multiOptions' => array('' => '[ None ]') + $pages, 'required' => true)), 'include_www' => array('checkbox', array('label' => 'Include www')))));
     $form->addSubForm(new Curry_Form_MultiForm(array('legend' => '', 'cloneTarget' => $domainForm, 'defaults' => $config->curry->domainMapping->domains ? $config->curry->domainMapping->domains->toArray() : array())), 'domainMapping');
     $form->addElement('submit', 'save', array('label' => 'Save'));
     if (isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         if (!$config->curry->domainMapping) {
             $config->curry->domainMapping = array();
         }
         $config->curry->domainMapping->enabled = count($values['domainMapping']) ? (bool) $values['enabled'] : false;
         $config->curry->domainMapping->default = $values['default_base_page'];
         $config->curry->domainMapping->domains = $values['domainMapping'];
         try {
             $writer = new Zend_Config_Writer_Array();
             $writer->write(Curry_Core::$config->curry->configPath, $config);
             if (extension_loaded('apc')) {
                 if (function_exists('apc_delete_file')) {
                     @apc_delete_file(Curry_Core::$config->curry->configPath);
                 } else {
                     @apc_clear_cache();
                 }
             }
             $this->addMessage("Settings saved.", self::MSG_SUCCESS);
         } catch (Exception $e) {
             $this->addMessage($e->getMessage(), self::MSG_ERROR);
         }
     }
     $this->addMainContent($form);
 }
Ejemplo n.º 14
0
 public function clear_feed_cache()
 {
     $d = dir($this->feather->forum_env['FORUM_CACHE_DIR']);
     $d = $this->hook->fire('options.clear_feed_cache.directory', $d);
     while (($entry = $d->read()) !== false) {
         if (substr($entry, 0, 10) == 'cache_feed' && substr($entry, -4) == '.php') {
             @unlink($this->feather->forum_env['FORUM_CACHE_DIR'] . $entry);
         }
         if (function_exists('opcache_invalidate')) {
             opcache_invalidate($this->feather->forum_env['FORUM_CACHE_DIR'] . $entry, true);
         } elseif (function_exists('apc_delete_file')) {
             @apc_delete_file($this->feather->forum_env['FORUM_CACHE_DIR'] . $entry);
         }
     }
     $d->close();
 }
Ejemplo n.º 15
0
 /**
  *
  *
  * @return bool|null
  * @throws Exception
  */
 public function save()
 {
     if (!$this->Dirty) {
         return null;
     }
     $this->EventArguments['ConfigDirty'] =& $this->Dirty;
     $this->EventArguments['ConfigNoSave'] = false;
     $this->EventArguments['ConfigType'] = $this->Type;
     $this->EventArguments['ConfigSource'] = $this->Source;
     $this->EventArguments['ConfigData'] = $this->Settings;
     $this->fireEvent('BeforeSave');
     if ($this->EventArguments['ConfigNoSave']) {
         $this->Dirty = false;
         return true;
     }
     // Check for and fire callback if one exists
     if ($this->Callback && is_callable($this->Callback)) {
         $CallbackOptions = array();
         if (!is_array($this->CallbackOptions)) {
             $this->CallbackOptions = array();
         }
         $CallbackOptions = array_merge($CallbackOptions, $this->CallbackOptions, array('ConfigDirty' => $this->Dirty, 'ConfigType' => $this->Type, 'ConfigSource' => $this->Source, 'ConfigData' => $this->Settings, 'SourceObject' => $this));
         $ConfigSaved = call_user_func($this->Callback, $CallbackOptions);
         if ($ConfigSaved) {
             $this->Dirty = false;
             return true;
         }
     }
     switch ($this->Type) {
         case 'file':
             if (empty($this->Source)) {
                 trigger_error(errorMessage('You must specify a file path to be saved.', 'Configuration', 'Save'), E_USER_ERROR);
             }
             $CheckWrite = $this->Source;
             if (!file_exists($CheckWrite)) {
                 $CheckWrite = dirname($CheckWrite);
             }
             if (!is_writable($CheckWrite)) {
                 throw new Exception(sprintf(t("Unable to write to config file '%s' when saving."), $this->Source));
             }
             $Group = $this->Group;
             $Data =& $this->Settings;
             ksort($Data);
             // Check for the case when the configuration is the group.
             if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) {
                 $Data = $Data[$Group];
             }
             // Do a sanity check on the config save.
             if ($this->Source == Gdn::config()->defaultPath()) {
                 // Log root config changes
                 try {
                     $LogData = $this->Initial;
                     $LogData['_New'] = $this->Settings;
                     LogModel::insert('Edit', 'Configuration', $LogData);
                 } catch (Exception $Ex) {
                 }
                 if (!isset($Data['Database'])) {
                     if ($Pm = Gdn::pluginManager()) {
                         $Pm->EventArguments['Data'] = $Data;
                         $Pm->EventArguments['Backtrace'] = debug_backtrace();
                         $Pm->fireEvent('ConfigError');
                     }
                     return false;
                 }
             }
             // Write config data to string format, ready for saving
             $FileContents = Gdn_Configuration::format($Data, array('VariableName' => $Group, 'WrapPHP' => true, 'ByLine' => true));
             if ($FileContents === false) {
                 trigger_error(errorMessage('Failed to define configuration file contents.', 'Configuration', 'Save'), E_USER_ERROR);
             }
             // Save to cache if we're into that sort of thing
             $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $this->Source);
             if ($this->Configuration && $this->Configuration->caching() && Gdn::cache()->type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::cache()->activeEnabled()) {
                 $CachedConfigData = Gdn::cache()->store($FileKey, $Data, array(Gdn_Cache::FEATURE_NOPREFIX => true, Gdn_Cache::FEATURE_EXPIRY => 3600));
             }
             $TmpFile = tempnam(PATH_CONF, 'config');
             $Result = false;
             if (file_put_contents($TmpFile, $FileContents) !== false) {
                 chmod($TmpFile, 0775);
                 $Result = rename($TmpFile, $this->Source);
             }
             if ($Result) {
                 if (function_exists('apc_delete_file')) {
                     // This fixes a bug with some configurations of apc.
                     @apc_delete_file($this->Source);
                 } elseif (function_exists('opcache_invalidate')) {
                     @opcache_invalidate($this->Source);
                 }
             }
             $this->Dirty = false;
             return $Result;
             break;
         case 'json':
         case 'array':
         case 'string':
             /**
              * How would these even save? String config data must be handled by
              * an event hook or callback, if at all.
              */
             $this->Dirty = false;
             return false;
             break;
     }
 }
Ejemplo n.º 16
0
 /**
  * A version of file_put_contents() that is multi-thread safe.
  *
  * @param string $filename Path to the file where to write the data.
  * @param mixed $data The data to write. Can be either a string, an array or a stream resource.
  * @param int $mode The permissions to set on a new file.
  * @return boolean
  * @category Filesystem Functions
  * @see http://php.net/file_put_contents
  */
 private static function filePutContents($filename, $data, $mode = 0644)
 {
     $temp = tempnam(dirname($filename), 'atomic');
     if (!($fp = @fopen($temp, 'wb'))) {
         $temp = dirname($filename) . DIRECTORY_SEPARATOR . uniqid('atomic');
         if (!($fp = @fopen($temp, 'wb'))) {
             trigger_error("AddonManager::filePutContents(): error writing temporary file '{$temp}'", E_USER_WARNING);
             return false;
         }
     }
     fwrite($fp, $data);
     fclose($fp);
     if (!@rename($temp, $filename)) {
         $r = @unlink($filename);
         $r &= @rename($temp, $filename);
         if (!$r) {
             trigger_error("AddonManager::filePutContents(): error writing file '{$filename}'", E_USER_WARNING);
             return false;
         }
     }
     if (function_exists('apc_delete_file')) {
         // This fixes a bug with some configurations of apc.
         apc_delete_file($filename);
     } elseif (function_exists('opcache_invalidate')) {
         opcache_invalidate($filename);
     }
     @chmod($filename, $mode);
     return true;
 }
 protected function saveToCurryConfig($values, &$config)
 {
     $this->ignoredPaths = (array) explode("\r\n", $values['ignore_paths']);
     // cleanup last empty value from array
     $this->ignoredPaths = array_filter($this->ignoredPaths, function ($val) {
         return !empty($val);
     });
     $this->ignoredFileExtensions = (array) explode("\r\n", $values['ignore_file_extensions']);
     $this->ignoredFileExtensions = array_filter($this->ignoredFileExtensions, function ($val) {
         return !empty($val);
     });
     $config->project->cleanup_file_system->ignore_paths = implode(',', $this->ignoredPaths);
     $config->project->cleanup_file_system->ignore_file_extensions = implode(',', $this->ignoredFileExtensions);
     try {
         $writer = new Zend_Config_Writer_Array();
         $writer->write(Curry_Core::$config->curry->configPath, $config);
         if (extension_loaded('apc')) {
             if (function_exists('apc_delete_file')) {
                 @apc_delete_file(Curry_Core::$config->curry->configPath);
             } else {
                 @apc_clear_cache();
             }
         }
         $this->addMessage("Settings saved.", self::MSG_SUCCESS);
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 18
0
function fluxbb_invalidate_cached_file($file)
{
    if (function_exists('opcache_invalidate')) {
        opcache_invalidate($file, true);
    } elseif (function_exists('apc_delete_file')) {
        @apc_delete_file($file);
    }
}
Ejemplo n.º 19
0
 /**
  * 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;
 }
Ejemplo n.º 20
0
 /**
  * Try to reset file from caches
  */
 public static function cleanFile($file)
 {
     // APC
     if (function_exists('apc_delete_file') && ini_get('apc.stat') == 0) {
         apc_delete_file($file);
     }
 }
Ejemplo n.º 21
0
 private function opCacheInvalidate($filepath)
 {
     if (is_file($filepath)) {
         if (function_exists('opcache_invalidate')) {
             @opcache_invalidate($filepath, $force = true);
         }
         if (function_exists('apc_delete_file')) {
             @apc_delete_file($filepath);
         }
     }
 }
Ejemplo n.º 22
0
function luna_write_cache_file($file, $content)
{
    $fh = @fopen(FORUM_CACHE_DIR . $file, 'wb');
    if (!$fh) {
        error('Unable to write cache file ' . luna_htmlspecialchars($file) . ' to cache directory. Please make sure PHP has write access to the directory \'' . luna_htmlspecialchars(FORUM_CACHE_DIR) . '\'', __FILE__, __LINE__);
    }
    flock($fh, LOCK_EX);
    ftruncate($fh, 0);
    fwrite($fh, $content);
    flock($fh, LOCK_UN);
    fclose($fh);
    if (function_exists('apc_delete_file')) {
        @apc_delete_file(FORUM_CACHE_DIR . $file);
    }
}
Ejemplo n.º 23
0
 public static function clear()
 {
     foreach (self::$_includedFiles as $cachefile => $ok) {
         if (function_exists('opcache_invalidate')) {
             opcache_invalidate($cachefile, true);
         } else {
             if (function_exists('apc_delete_file')) {
                 apc_delete_file($cachefile);
             }
         }
     }
     self::$_includedFiles = array();
 }
Ejemplo n.º 24
0
/**
 * Invalidates a PHP file from any active opcode caches.
 *
 * If the opcode cache does not support the invalidation of individual files,
 * the entire cache will be flushed.
 * kudo : http://cgit.drupalcode.org/drupal/commit/?id=be97f50
 *
 * @param string $filepath
 *   The absolute path of the PHP file to invalidate.
 */
function spip_clear_opcode_cache($filepath)
{
    spip_clearstatcache(true, $filepath);
    // Zend OPcache
    if (function_exists('opcache_invalidate')) {
        opcache_invalidate($filepath, true);
    }
    // APC.
    if (function_exists('apc_delete_file')) {
        // apc_delete_file() throws a PHP warning in case the specified file was
        // not compiled yet.
        // @see http://php.net/apc-delete-file
        @apc_delete_file($filepath);
    }
}
Ejemplo n.º 25
0
function apc_delete_directory($dir, $cache = false)
{
    if ($cache == false) {
        $cache = $GLOBALS['cache'];
    }
    foreach ($cache['cache_list'] as $list) {
        if ($list['type'] == 'file') {
            if (strcmp($dir, $list['filename']) >= 0) {
                apc_delete_file($list['filename']);
            }
        }
    }
    return true;
}
Ejemplo n.º 26
0
 public static function dispatchUtils()
 {
     if ($_POST['password'] != self::_getHttpPassword()) {
         throw new Kwf_Exception_AccessDenied();
     }
     $uri = $_SERVER['REQUEST_URI'];
     $baseUrl = Kwf_Setup::getBaseUrl();
     if ($baseUrl && substr($uri, 0, strlen($baseUrl)) == $baseUrl) {
         $uri = substr($uri, strlen($baseUrl));
     }
     if (substr($uri, 0, 25) == '/kwf/util/apc/clear-cache') {
         $s = microtime(true);
         if (isset($_REQUEST['deleteCacheSimple'])) {
             foreach (explode(',', $_REQUEST['deleteCacheSimple']) as $id) {
                 Kwf_Cache_Simple::delete($id);
             }
         }
         if (isset($_REQUEST['clearCacheSimpleStatic'])) {
             foreach (explode(',', $_REQUEST['clearCacheSimpleStatic']) as $id) {
                 Kwf_Cache_SimpleStatic::clear($id);
             }
         }
         if (isset($_REQUEST['deleteCacheSimpleStatic'])) {
             foreach (explode(',', $_REQUEST['deleteCacheSimpleStatic']) as $id) {
                 Kwf_Cache_SimpleStatic::delete($id);
             }
         }
         if (isset($_REQUEST['cacheIds'])) {
             foreach (explode(',', $_REQUEST['cacheIds']) as $cacheId) {
                 apc_delete($cacheId);
             }
         }
         if (isset($_REQUEST['files']) && function_exists('apc_delete_file')) {
             foreach (explode(',', $_REQUEST['files']) as $file) {
                 @apc_delete_file($file);
             }
         } else {
             if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'user') {
                 if (extension_loaded('apcu')) {
                     apc_clear_cache();
                 } else {
                     apc_clear_cache('user');
                 }
             } else {
                 if (!extension_loaded('apcu')) {
                     apc_clear_cache('file');
                 }
             }
         }
         echo 'OK ' . round((microtime(true) - $s) * 1000) . ' ms';
         exit;
     } else {
         if (substr($uri, 0, 24) == '/kwf/util/apc/save-cache') {
             $data = unserialize($_REQUEST['data']);
             if (apc_store($_REQUEST['id'], $data)) {
                 echo 'OK';
             } else {
                 echo 'ERROR';
             }
             exit;
         } else {
             if (substr($uri, 0, 31) == '/kwf/util/apc/get-counter-value') {
                 $prefix = Kwf_Cache::getUniquePrefix() . 'bench-';
                 echo apc_fetch($prefix . $_GET['name']);
                 exit;
             } else {
                 if ($uri == '/kwf/util/apc/stats') {
                     self::stats();
                 } else {
                     if ($uri == '/kwf/util/apc/iterate') {
                         self::iterate();
                     } else {
                         if ($uri == '/kwf/util/apc/is-loaded') {
                             if (extension_loaded('apc')) {
                                 echo 'OK1';
                             } else {
                                 echo 'OK0';
                             }
                             exit;
                         } else {
                             if ($uri == '/kwf/util/apc/get-hostname') {
                                 echo php_uname('n');
                                 exit;
                             }
                         }
                     }
                 }
             }
         }
     }
     throw new Kwf_Exception_NotFound();
 }
Ejemplo n.º 27
0
 /**
  * Save the config file.
  *
  * @param Zend_Config $config
  * @param array $values
  */
 private function saveSettings(&$config, array $values)
 {
     // General
     self::setvar($config->curry, 'name', $values['general']['name']);
     self::setvar($config->curry, 'baseUrl', $values['general']['baseUrl']);
     self::setvar($config->curry, 'adminEmail', $values['general']['adminEmail']);
     $config->curry->divertOutMailToAdmin = (bool) $values['general']['divertOutMailToAdmin'];
     self::setvar($config->curry, 'fallbackLanguage', $values['general']['fallbackLanguage'] ? $values['general']['fallbackLanguage'] : null);
     $config->curry->developmentMode = (bool) $values['general']['developmentMode'];
     $config->curry->forceDomain = (bool) $values['general']['forceDomain'];
     // backend
     $config->curry->revisioning = (bool) $values['backend']['revisioning'];
     $config->curry->autoPublish = (bool) $values['backend']['autoPublish'];
     $config->curry->backend->noauth = (bool) $values['backend']['noauth'];
     self::setvar($config->curry, 'defaultEditor', $values['backend']['defaultEditor']);
     self::setvar($config->curry->backend, 'theme', $values['backend']['theme']);
     self::setvar($config->curry->backend, 'templatePage', $values['backend']['templatePage'] ? (int) $values['backend']['templatePage'] : null);
     self::setvar($config->curry->backend, 'logotype', $values['backend']['logotype']);
     self::setvar($config->curry, 'autoBackup', $values['backend']['autoBackup']);
     self::setvar($config->curry, 'autoUpdateIndex', $values['backend']['autoUpdateIndex']);
     // Live edit
     $excludedPlaceholders = array_filter(array_map('trim', explode(PHP_EOL, $values['liveEdit']['placeholderExclude'])));
     if (!count($excludedPlaceholders)) {
         $excludedPlaceholders = null;
     }
     $config->curry->liveEdit = (bool) $values['liveEdit']['liveEdit'];
     self::setvar($config->curry->backend, 'placeholderExclude', $excludedPlaceholders);
     // Encoding
     self::setvar($config->curry, 'internalEncoding', $values['encoding']['internal']);
     self::setvar($config->curry, 'outputEncoding', $values['encoding']['output']);
     // Paths
     self::setvar($config->curry, 'basePath', $values['paths']['basePath']);
     self::setvar($config->curry, 'projectPath', $values['paths']['projectPath']);
     self::setvar($config->curry, 'wwwPath', $values['paths']['wwwPath']);
     self::setvar($config->curry, 'vendorPath', $values['paths']['vendorPath']);
     // Mail
     if ($values['mail']['method']) {
         if (!$config->curry->mail) {
             $config->curry->mail = array();
         }
         $config->curry->mail->method = $values['mail']['method'];
         // Smtp
         if ($values['mail']['method'] == 'smtp') {
             $config->curry->mail->host = $values['mail']['host'];
             if (!$config->curry->mail->options) {
                 $config->curry->mail->options = array();
             }
             self::setvar($config->curry->mail->options, 'port', $values['mail']['port']);
             self::setvar($config->curry->mail->options, 'ssl', $values['mail']['ssl']);
             self::setvar($config->curry->mail->options, 'auth', $values['mail']['auth']);
             self::setvar($config->curry->mail->options, 'username', $values['mail']['username']);
             self::setvar($config->curry->mail->options, 'password', $values['mail']['password']);
         }
     } else {
         if (isset($config->curry->mail->method)) {
             unset($config->curry->mail->method);
         }
     }
     // Misc
     $config->curry->errorNotification = (bool) $values['misc']['error_notification'];
     $config->curry->propel->logging = (bool) $values['misc']['log_propel'];
     $config->curry->propel->debug = (bool) $values['misc']['debug_propel'];
     if ($values['misc']['log']) {
         $config->curry->log->method = $values['misc']['log'];
     }
     $config->curry->updateTranslationStrings = (bool) $values['misc']['update_translations'];
     // Error pages
     $config->curry->errorPage->notFound = $values['errorPage']['notFound'] ? (int) $values['errorPage']['notFound'] : null;
     $config->curry->errorPage->unauthorized = $values['errorPage']['unauthorized'] ? (int) $values['errorPage']['unauthorized'] : null;
     $config->curry->errorPage->error = $values['errorPage']['error'] ? (int) $values['errorPage']['error'] : null;
     // Maintenance
     $config->curry->maintenance->enabled = (bool) $values['maintenance']['enabled'];
     $config->curry->maintenance->page = $values['maintenance']['page'] ? (int) $values['maintenance']['page'] : null;
     $config->curry->maintenance->message = $values['maintenance']['message'];
     // Set migration version if missing
     if (!isset($config->curry->migrationVersion)) {
         $config->curry->migrationVersion = Curry_Core::MIGRATION_VERSION;
     }
     // Unset upgrade version if present
     if (isset($config->curry->upgradeVersion)) {
         unset($config->curry->upgradeVersion);
     }
     try {
         $writer = new Zend_Config_Writer_Array();
         $writer->write(Curry_Core::$config->curry->configPath, $config);
         if (extension_loaded('apc')) {
             if (function_exists('apc_delete_file')) {
                 @apc_delete_file(Curry_Core::$config->curry->configPath);
             } else {
                 @apc_clear_cache();
             }
         }
         $this->addMessage("Settings saved.", self::MSG_SUCCESS);
     } catch (Exception $e) {
         $this->addMessage($e->getMessage(), self::MSG_ERROR);
     }
 }
Ejemplo n.º 28
0
 /**
  *
  */
 protected function apcDelete()
 {
     if (!extension_loaded('apc') || !ini_get('apc.enabled') || !function_exists('apc_cache_info')) {
         return;
     }
     try {
         //delete files
         $data = apc_cache_info();
         if (is_array($data) && isset($data['cache_list']) && is_array($data['cache_list']) && count($data['cache_list'])) {
             foreach ($data['cache_list'] as $file) {
                 if ($file['type'] == 'file') {
                     apc_delete_file($file['filename']);
                     if (YII_DEBUG) {
                         //                            echo $file['filename'] . "\n";
                     }
                 }
             }
         }
         apc_clear_cache();
         apc_clear_cache('opcode');
         apc_clear_cache('user');
         if (YII_DEBUG) {
             //                echo 'APC cache is cleared.' . "\n";
         }
     } catch (Exception $ex) {
         //            echo 'Cannot delete APC cache: ' . $ex->getMessage();
     }
 }
Ejemplo n.º 29
0
 protected static function write($data, $to)
 {
     $a = PATCHWORK_PROJECT_PATH . '.~' . uniqid(mt_rand(), true);
     if (false !== file_put_contents($a, $data)) {
         function_exists('apc_delete_file') ? touch($a, filemtime($to)) : touch($a, filemtime($to) + 1);
         // +1 to notify the change to opcode caches
         if ('\\' === DIRECTORY_SEPARATOR) {
             file_exists($to) && unlink($to);
             rename($a, $to) || unlink($a);
         } else {
             rename($a, $to);
         }
         function_exists('apc_delete_file') && apc_delete_file($to);
     }
 }
Ejemplo n.º 30
0
 /**
  * @param string $path
  *
  * @throws \RuntimeException
  */
 protected function invalidateSystemCacheForFile($path)
 {
     if (ini_get('apc.enabled')) {
         if (apc_exists($path) && !apc_delete_file($path)) {
             throw new \RuntimeException(sprintf('Failed to clear APC Cache for file %s', $path));
         }
     } elseif ('cli' === php_sapi_name() ? ini_get('opcache.enable_cli') : ini_get('opcache.enable')) {
         if (!opcache_invalidate($path, true)) {
             throw new \RuntimeException(sprintf('Failed to clear OPCache for file %s', $path));
         }
     }
 }