Ejemplo n.º 1
0
 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
 {
     switch ($mode) {
         case Zend_Cache::CLEANING_MODE_ALL:
             $ret = true;
             if (PHP_SAPI == 'cli') {
                 if (Kwf_Config::getValue('externalClearCacheScript')) {
                     throw new Kwf_Exception("Dont't delete complete apc-user cache via cli.");
                 }
                 $ret = Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'));
             }
             if (extension_loaded('apcu')) {
                 return $ret && apc_clear_cache('user');
             } else {
                 return $ret && apc_clear_cache();
             }
             break;
         case Zend_Cache::CLEANING_MODE_OLD:
             $this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
             break;
         case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
             $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
             break;
         default:
             Zend_Cache::throwException('Invalid mode for clean() method');
             break;
     }
 }
Ejemplo n.º 2
0
 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
 {
     switch ($mode) {
         case Zend_Cache::CLEANING_MODE_ALL:
             $ret = true;
             if (php_sapi_name() == 'cli') {
                 $ret = Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'));
             }
             if (extension_loaded('apcu')) {
                 return $ret && apc_clear_cache('user');
             } else {
                 return $ret && apc_clear_cache();
             }
             break;
         case Zend_Cache::CLEANING_MODE_OLD:
             $this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
             break;
         case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
             $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
             break;
         default:
             Zend_Cache::throwException('Invalid mode for clean() method');
             break;
     }
 }
Ejemplo n.º 3
0
 protected function _clearCache($options)
 {
     $options['outputFn'] = array($this, 'outputFn');
     if (PHP_SAPI == 'cli') {
         Kwf_Util_Apc::callClearCacheByCli(array('type' => 'file'), $options);
     } else {
         if (!extension_loaded('apcu')) {
             apc_clear_cache('file');
         }
     }
 }
Ejemplo n.º 4
0
 public static function restoreMaintenanceBootstrapSelf($output = true)
 {
     if (!file_exists('bootstrap.php.backup')) {
         throw new Kwf_Exception("maintenance bootstrap not written");
     }
     unlink('bootstrap.php');
     rename('bootstrap.php.backup', 'bootstrap.php');
     if ($output) {
         echo "\nrestored bootstrap.php\n";
     }
     Kwf_Util_Apc::callClearCacheByCli(array('files' => getcwd() . '/bootstrap.php'));
 }
Ejemplo n.º 5
0
 protected function _clearCache($options)
 {
     $options['outputFn'] = array($this, 'outputFn');
     if (php_sapi_name() == 'cli') {
         Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'), $options);
     } else {
         if (extension_loaded('apcu')) {
             apc_clear_cache();
         } else {
             apc_clear_cache('user');
         }
     }
 }
Ejemplo n.º 6
0
 public static function reload()
 {
     $configClass = Kwf_Setup::$configClass;
     $config = new $configClass(Kwf_Setup::getConfigSection());
     $cacheId = 'config_' . str_replace(array('-', '.'), '_', Kwf_Setup::getConfigSection());
     Kwf_Config_Cache::getInstance()->save($config, $cacheId);
     if (extension_loaded('apc')) {
         $apcCacheId = $cacheId . getcwd();
         apc_delete($apcCacheId);
         apc_delete($apcCacheId . 'mtime');
         if (PHP_SAPI == 'cli') {
             Kwf_Util_Apc::callClearCacheByCli(array(array('cacheIds' => $apcCacheId . ',' . $apcCacheId . 'mtime')));
         }
         Kwf_Cache_SimpleStatic::clear('config-');
     }
     Kwf_Config_Web::clearInstances();
     Kwf_Registry::set('config', $config);
 }
 protected function setUp()
 {
     if (!($cfg = Kwf_Registry::get('testServerConfig'))) {
         throw new Kwf_Exception("testServerConfig not set");
     }
     Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'));
     Kwf_Cache::factory('Core', 'Memcached', array('lifetime' => null, 'automatic_cleaning_factor' => false, 'automatic_serialization' => true))->clean();
     $d = $this->_domain;
     if (!$d) {
         $domain = $cfg->server->domain;
     } else {
         if (!isset($cfg->kwc->domains->{$d})) {
             throw new Kwf_Exception("Domain '{$d}' not found in config");
         }
         $domain = $cfg->kwc->domains->{$d}->domain;
     }
     $this->setBrowserUrl('http://' . $domain . '/');
     $this->_unitTestCookie = md5(uniqid('testId', true));
     $this->captureScreenshotOnFailure = Kwf_Setup::getConfigSection() == 'vivid-test-server';
     $this->screenshotPath = '/mnt/screenshots';
     $this->screenshotUrl = 'http://screenshots.vivid';
     parent::setUp();
 }
Ejemplo n.º 8
0
 public static function delete($cacheIds)
 {
     if (!is_array($cacheIds)) {
         $cacheIds = array($cacheIds);
     }
     $ret = true;
     $ids = array();
     foreach ($cacheIds as $cacheId) {
         if (self::getBackend() == 'memcache') {
             $r = self::getMemcache()->delete(self::_getMemcachePrefix() . $cacheId);
         } else {
             if (self::getBackend() == 'apc') {
                 static $prefix;
                 if (!isset($prefix)) {
                     $prefix = self::getUniquePrefix() . '-';
                 }
                 $r = apc_delete($prefix . $cacheId);
                 $ids[] = $prefix . $cacheId;
             } else {
                 if (self::getBackend() == 'file') {
                     $r = true;
                     $file = self::_getFileNameForCacheId($cacheId);
                     if (!file_exists($file)) {
                         $r = false;
                     } else {
                         if (!unlink($file)) {
                             $r = false;
                         }
                     }
                 } else {
                     if (!isset(self::$_zendCache)) {
                         self::getZendCache();
                     }
                     $r = self::$_zendCache->remove(self::_processId($cacheId));
                 }
             }
         }
         if (!$r) {
             $ret = false;
         }
     }
     if (self::getBackend() == 'apc' && PHP_SAPI == 'cli' && $ids) {
         $ret = Kwf_Util_Apc::callClearCacheByCli(array('cacheIds' => implode(',', $ids)));
     }
     return $ret;
 }
Ejemplo n.º 9
0
 private static function _clearApcCache($params)
 {
     echo "APC: ";
     foreach ($params as $k => $i) {
         if (is_array($i)) {
             $params[$k] = implode(',', $i);
         }
     }
     Kwf_Util_Apc::callClearCacheByCli($params, array('outputFn' => 'printf'));
 }
Ejemplo n.º 10
0
 public static function delete($cacheIds)
 {
     if (!is_array($cacheIds)) {
         $cacheIds = array($cacheIds);
     }
     if (self::getBackend() == 'redis') {
         foreach ($cacheIds as &$id) {
             $id = 'simple:' . self::$namespace . ':' . $id;
         }
         return self::getRedis()->delete($cacheIds);
     }
     $ret = true;
     foreach ($cacheIds as $cacheId) {
         if (self::getBackend() == 'memcache') {
             $r = self::getMemcache()->delete(self::_getMemcachePrefix() . md5($cacheId));
         } else {
             if (self::getBackend() == 'apc') {
                 static $prefix;
                 if (!isset($prefix)) {
                     $prefix = self::$uniquePrefix . '-';
                 }
                 $r = apc_delete($prefix . $cacheId);
             } else {
                 if (self::getBackend() == 'apcu') {
                     static $prefix;
                     if (!isset($prefix)) {
                         $prefix = self::$uniquePrefix . '-';
                     }
                     $r = apcu_delete($prefix . $cacheId);
                 } else {
                     if (self::getBackend() == 'file') {
                         $r = true;
                         $file = self::_getFileNameForCacheId($cacheId);
                         if (!file_exists($file)) {
                             $r = false;
                         } else {
                             if (!unlink($file)) {
                                 $r = false;
                             }
                         }
                     } else {
                         if (!isset(self::$_zendCache)) {
                             self::getZendCache();
                         }
                         $r = self::$_zendCache->remove(self::_processId($cacheId));
                     }
                 }
             }
         }
         if (!$r) {
             $ret = false;
         }
     }
     if ((self::getBackend() == 'apc' || self::getBackend() == 'apcu') && PHP_SAPI == 'cli') {
         $ret = Kwf_Util_Apc::callClearCacheByCli(array('deleteCacheSimple' => implode(',', $cacheIds)));
     }
     return $ret;
 }
Ejemplo n.º 11
0
 protected function _refreshCache($options)
 {
     file_put_contents('cache/setup' . Kwf_Setup::CACHE_SETUP_VERSION . '.php', Kwf_Util_Setup::generateCode(Kwf_Setup::$configClass));
     Kwf_Util_Apc::callClearCacheByCli(array('files' => getcwd() . '/cache/setup' . Kwf_Setup::CACHE_SETUP_VERSION . '.php'));
 }
Ejemplo n.º 12
0
 public static function clearApcUser()
 {
     if ($cmd = Kwf_Config::getValue('externalClearCacheScript')) {
         $cmd .= ' apc-user';
         exec($cmd, $output, $ret);
         if ($ret) {
             echo "\n\n" . implode("\n   ", $output) . "\n";
             throw new Kwf_Exception("Error with external script: {$cmd}");
         }
     } else {
         Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'));
     }
 }
Ejemplo n.º 13
0
 /**
  * Delete static cache, don't use except in unittests
  *
  * @internal
  */
 public static function _delete($cacheIds)
 {
     if (!is_array($cacheIds)) {
         $cacheIds = array($cacheIds);
     }
     $ret = true;
     if (!extension_loaded('apc')) {
         foreach ($cacheIds as $cacheId) {
             $file = self::_getFileNameForCacheId($cacheId);
             if (!file_exists($file)) {
                 $ret = false;
             } else {
                 if (!unlink($file)) {
                     $ret = false;
                 }
             }
         }
     } else {
         $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-';
         $ids = array();
         foreach ($cacheIds as $cacheId) {
             if (!apc_delete($prefix . $cacheId)) {
                 $ret = false;
             }
             $ids[] = $prefix . $cacheId;
         }
         if (PHP_SAPI == 'cli' && $ids) {
             $result = Kwf_Util_Apc::callClearCacheByCli(array('cacheIds' => implode(',', $ids)));
             if (!$result['result']) {
                 $ret = false;
             }
         }
     }
     return $ret;
 }
 /**
  * Delete static cache, don't use except in unittests
  *
  * @internal
  */
 public static function _delete($cacheIds)
 {
     if (!is_array($cacheIds)) {
         $cacheIds = array($cacheIds);
     }
     $ret = true;
     if (!extension_loaded('apc') || PHP_SAPI == 'cli') {
         foreach ($cacheIds as $cacheId) {
             unset(self::$_cache[$cacheId]);
             $file = self::_getFileNameForCacheId($cacheId);
             if (!file_exists($file)) {
                 $ret = false;
             } else {
                 if (!unlink($file)) {
                     $ret = false;
                 }
             }
         }
         if (extension_loaded('apc')) {
             $result = Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic' => implode(',', $cacheIds)));
             if (!$result['result']) {
                 $ret = false;
             }
         }
     } else {
         $prefix = Kwf_Cache_Simple::$uniquePrefix . '-';
         foreach ($cacheIds as $cacheId) {
             if (!apc_delete($prefix . $cacheId)) {
                 $ret = false;
             }
         }
     }
     return $ret;
 }