상속: implements cachemanager
예제 #1
0
 private function connect()
 {
     $func = Config::get('cache_memcache_pconnect') ? 'memcache_pconnect' : 'memcache_connect';
     if (!(self::$connection = @$func($this->host, $this->port))) {
         throw new CacheException("Couldn't connect to memcache server");
     }
 }
예제 #2
0
 /**
  * Connect to memcache server
  */
 public function connect()
 {
     $this->memcache = new Memcache();
     $servers = CacheMemcache::getMemcachedServers();
     if (!$servers) {
         return false;
     }
     foreach ($servers as $server) {
         $this->memcache->addServer($server['ip'], $server['port'], $server['weight']);
     }
     $this->is_connected = true;
 }
예제 #3
0
 private static function connect()
 {
     if (self::$memcache) {
         return;
     }
     self::$memcache = new Memcache();
     self::$memcache->addServer(MEMCACHE_HOST, MEMCACHE_PORT);
     self::$requestStats['get'] = 0;
     self::$requestStats['set'] = 0;
     self::$requestStats['del'] = 0;
     // make sure connection will be closed on request shutdown
     register_shutdown_function(array(__CLASS__, 'close'));
 }
예제 #4
0
    public function postProcess()
    {
        /* PrestaShop demo mode */
        if (_PS_MODE_DEMO_) {
            $this->errors[] = Tools::displayError('This functionality has been disabled.');
            return;
        }
        Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this));
        if (Tools::isSubmit('submitAddServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (!Tools::getValue('memcachedIp')) {
                    $this->errors[] = Tools::displayError('The Memcached IP is missing.');
                }
                if (!Tools::getValue('memcachedPort')) {
                    $this->errors[] = Tools::displayError('The Memcached port is missing.');
                }
                if (!Tools::getValue('memcachedWeight')) {
                    $this->errors[] = Tools::displayError('The Memcached weight is missing.');
                }
                if (!count($this->errors)) {
                    if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) {
                        Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                    } else {
                        $this->errors[] = Tools::displayError('The Memcached server cannot be added.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to add this.');
            }
        }
        if (Tools::getValue('deleteMemcachedServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) {
                    Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                } else {
                    $this->errors[] = Tools::displayError('There was an error when attempting to delete the Memcached server.');
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to delete this.');
            }
        }
        $redirectAdmin = false;
        if ((bool) Tools::getValue('smarty_up')) {
            if ($this->tabAccess['edit'] === '1') {
                Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
                Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
                Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0));
                Configuration::updateValue('PS_SMARTY_CONSOLE_KEY', Tools::getValue('smarty_console_key', 'SMARTY_DEBUG'));
                $redirecAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('features_detachables_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Tools::getValue('combination') || !Combination::isCurrentlyUsed()) {
                    Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination'));
                }
                if (Tools::getValue('customer_group') && !Group::isCurrentlyUsed()) {
                    Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', Tools::getValue('customer_group'));
                }
                Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature'));
                $redirectAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('ccc_up')) {
            if ($this->tabAccess['edit'] === '1') {
                $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/';
                if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) {
                    $this->errors[] = Tools::displayError(sprintf($this->l('To use Smart Cache directory %s must be writable.'), realpath($theme_cache_directory)));
                }
                if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
                    $this->errors[] = Tools::displayError('Unknown error.');
                } else {
                    $redirectAdmin = true;
                    if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
                        Tools::generateHtaccess();
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('media_server_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
                    $this->errors[] = Tools::displayError('Media server #1 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
                    $this->errors[] = Tools::displayError('Media server #2 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
                    $this->errors[] = Tools::displayError('Media server #3 is invalid');
                }
                if (!count($this->errors)) {
                    $base_urls = array();
                    $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
                    $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
                    $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
                    if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 1);
                    } else {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 0);
                    }
                    rewriteSettingsFile($base_urls, null, null);
                    Tools::clearSmartyCache();
                    Media::clearCache();
                    Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_']));
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
                    $redirectAdmin = true;
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) {
            if ($this->tabAccess['edit'] === '1') {
                $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM');
                $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php');
                $new_settings = $prev_settings;
                if ($algo) {
                    if (!function_exists('mcrypt_encrypt')) {
                        $this->errors[] = Tools::displayError('The "Mcrypt" PHP extension is not activated on this server.');
                    } else {
                        if (!strstr($new_settings, '_RIJNDAEL_KEY_')) {
                            $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $key = Tools::passwdGen($key_size);
                            $new_settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $new_settings);
                        }
                        if (!strstr($new_settings, '_RIJNDAEL_IV_')) {
                            $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND));
                            $new_settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $new_settings);
                        }
                    }
                }
                if (!count($this->errors)) {
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) {
                        Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo);
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('cache_up')) {
            if ($this->tabAccess['edit'] === '1') {
                $new_settings = $prev_settings = file_get_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php');
                $cache_active = (bool) Tools::getValue('cache_active');
                if ($caching_system = Tools::getValue('caching_system')) {
                    $new_settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]*)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $new_settings);
                } else {
                    $cache_active = false;
                    $this->errors[] = Tools::displayError('The caching system is missing.');
                }
                if ($cache_active) {
                    if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
                        $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.') . '
							<a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
                    } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc')) {
                        $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.') . '
							<a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
                    } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
                        $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.') . '
							<a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
                    } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) {
                        $this->errors[] = Tools::displayError('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).') . '
							<a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>';
                    } elseif ($caching_system == 'CacheFs') {
                        if (!is_dir(_PS_CACHEFS_DIRECTORY_)) {
                            @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true);
                        } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) {
                            $this->errors[] = sprintf(Tools::displayError('To use CacheFS, the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_));
                        }
                    }
                    if ($caching_system == 'CacheFs') {
                        if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
                            $this->errors[] = Tools::displayError('Please set a directory depth.');
                        }
                        if (!count($this->errors)) {
                            CacheFs::deleteCacheDirectory();
                            CacheFs::createCacheDirectories((int) $depth);
                            Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth);
                        }
                    } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') {
                        Cache::getInstance()->flush();
                    }
                }
                if (!count($this->errors)) {
                    $new_settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([01]?)\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $new_settings);
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if ($new_settings == $prev_settings || copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php') && (bool) file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) {
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('The settings file cannot be overwritten.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit this.');
            }
        }
        if ((bool) Tools::getValue('empty_smarty_cache')) {
            $redirectAdmin = true;
            Tools::clearSmartyCache();
            Tools::clearXMLCache();
            Media::clearCache();
            PrestaShopAutoload::getInstance()->generateIndex();
        }
        if (Tools::isSubmit('submitAddconfiguration') && _PS_MODE_DEV_) {
            Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module'));
            Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides'));
            if (Tools::getValue('overrides')) {
                PrestaShopAutoload::getInstance()->_include_override_path = false;
            }
            PrestaShopAutoload::getInstance()->generateIndex();
        }
        if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) {
            Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => ''));
            Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
        }
    }
 public function deleteFilterObject($deletePetMateListFilterObject)
 {
     $cache = new CacheMemcache();
     if ($cache->memcacheEnabled) {
         $email = $deletePetMateListFilterObject->getEmail();
         if ($email == $cache->getData('filter_pet_mate_list_email')) {
             $this->data = $cache->delData('filter_pet_mate_list_array_' + $email);
             // removing data from cache server
         }
     }
     return $this->data;
 }
    public function postProcess()
    {
        if (Tools::isSubmit('submitAddServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (!Tools::getValue('memcachedIp')) {
                    $this->errors[] = Tools::displayError('Memcached IP is missing');
                }
                if (!Tools::getValue('memcachedPort')) {
                    $this->errors[] = Tools::displayError('Memcached port is missing');
                }
                if (!Tools::getValue('memcachedWeight')) {
                    $this->errors[] = Tools::displayError('Memcached weight is missing');
                }
                if (!count($this->errors)) {
                    if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) {
                        Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                    } else {
                        $this->errors[] = Tools::displayError('Cannot add Memcached server');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to add here.');
            }
        }
        if (Tools::getValue('deleteMemcachedServer')) {
            if ($this->tabAccess['add'] === '1') {
                if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) {
                    Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                } else {
                    $this->errors[] = Tools::displayError('Error in deleting Memcached server');
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        }
        $redirecAdmin = false;
        if ((bool) Tools::getValue('smarty_up')) {
            if ($this->tabAccess['edit'] === '1') {
                Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
                Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
                Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0));
                $redirecAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ((bool) Tools::getValue('features_detachables_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (!Combination::isCurrentlyUsed()) {
                    Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination'));
                }
                Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature'));
                $redirecAdmin = true;
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ((bool) Tools::getValue('ccc_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HIGH_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HIGH_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
                    $this->errors[] = Tools::displayError('Unknown error.');
                } else {
                    $redirecAdmin = true;
                    if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
                        Tools::generateHtaccess();
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ((bool) Tools::getValue('media_server_up')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
                    $this->errors[] = Tools::displayError('Media server #1 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
                    $this->errors[] = Tools::displayError('Media server #2 is invalid');
                }
                if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
                    $this->errors[] = Tools::displayError('Media server #3 is invalid');
                }
                if (!count($this->errors)) {
                    $base_urls = array();
                    $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
                    $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
                    $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
                    rewriteSettingsFile($base_urls, null, null);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
                    unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
                    $redirecAdmin = true;
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ((bool) Tools::getValue('ciphering_up') && Configuration::get('PS_CIPHER_ALGORITHM') != (int) Tools::getValue('PS_CIPHER_ALGORITHM')) {
            if ($this->tabAccess['edit'] === '1') {
                $algo = (int) Tools::getValue('PS_CIPHER_ALGORITHM');
                $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php');
                if ($algo) {
                    if (!function_exists('mcrypt_encrypt')) {
                        $this->errors[] = Tools::displayError('PHP "Mcrypt" extension is not activated on this server.');
                    } else {
                        if (!strstr($settings, '_RIJNDAEL_KEY_')) {
                            $key_size = mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $key = Tools::passwdGen($key_size);
                            $settings = preg_replace('/define\\(\'_COOKIE_KEY_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_KEY_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_KEY_\', \'' . $key . '\');', $settings);
                        }
                        if (!strstr($settings, '_RIJNDAEL_IV_')) {
                            $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
                            $iv = base64_encode(mcrypt_create_iv($iv_size, MCRYPT_RAND));
                            $settings = preg_replace('/define\\(\'_COOKIE_IV_\', \'([a-z0-9=\\/+-_]+)\'\\);/i', 'define(\'_COOKIE_IV_\', \'\\1\');' . "\n" . 'define(\'_RIJNDAEL_IV_\', \'' . $iv . '\');', $settings);
                        }
                    }
                }
                if (!count($this->errors)) {
                    if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) {
                        Configuration::updateValue('PS_CIPHER_ALGORITHM', $algo);
                        $redirecAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('Cannot overwrite settings file.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ((bool) Tools::getValue('cache_up')) {
            if ($this->tabAccess['edit'] === '1') {
                $settings = file_get_contents(dirname(__FILE__) . '/../../config/settings.inc.php');
                if (!Tools::getValue('active')) {
                    $cache_active = 0;
                } else {
                    $cache_active = 1;
                }
                if (!($caching_system = Tools::getValue('caching_system'))) {
                    $this->errors[] = Tools::displayError('Caching system is missing');
                } else {
                    $settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]+)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $caching_system . '\');', $settings);
                }
                if ($cache_active && $caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
                    $this->errors[] = Tools::displayError('To use Memcached, you must install the Memcache PECL extension on your server.') . '
						<a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
                } else {
                    if ($cache_active && $caching_system == 'CacheApc' && !extension_loaded('apc')) {
                        $this->errors[] = Tools::displayError('To use APC cache, you must install the APC PECL extension on your server.') . '
						<a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
                    } else {
                        if ($cache_active && $caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
                            $this->errors[] = Tools::displayError('To use Xcache, you must install the Xcache extension on your server.') . '
						<a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
                        } else {
                            if ($cache_active && $caching_system == 'CacheFs' && !is_writable(_PS_CACHEFS_DIRECTORY_)) {
                                $this->errors[] = sprintf(Tools::displayError('To use CacheFS the directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_));
                            }
                        }
                    }
                }
                if ($caching_system == 'CacheFs' && $cache_active) {
                    if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
                        $this->errors[] = Tools::displayError('Please set a directory depth');
                    }
                    if (!count($this->errors)) {
                        CacheFs::deleteCacheDirectory();
                        CacheFs::createCacheDirectories((int) $depth);
                        Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth);
                    }
                } else {
                    if ($caching_system == 'MCached' && $cache_active && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'MCached') {
                        Cache::getInstance()->flush();
                    }
                }
                if (!count($this->errors)) {
                    $settings = preg_replace('/define\\(\'_PS_CACHE_ENABLED_\', \'([0-9])\'\\);/Ui', 'define(\'_PS_CACHE_ENABLED_\', \'' . (int) $cache_active . '\');', $settings);
                    if (file_put_contents(dirname(__FILE__) . '/../../config/settings.inc.php', $settings)) {
                        $redirecAdmin = true;
                    } else {
                        $this->errors[] = Tools::displayError('Cannot overwrite settings file.');
                    }
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        }
        if ($redirecAdmin) {
            Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
        } else {
            return parent::postProcess();
        }
    }
예제 #7
0
<?php

$memcache = new Memcache();
$memcache->connect('localhost', 11211) or die("Could not connect");
$aData = array('name' => 'table', 'color' => 'brown', 'size' => array('x' => 200, 'y' => 120, 'z' => 150), 'strength' => 10);
require_once 'memcache.caching.php';
$oCache = new CacheMemcache();
echo 'Initial data: <pre>';
// lets see what we have
print_r($aData);
echo '</pre>';
if ($oCache->bEnabled) {
    // if Memcache enabled
    $oCache->setData('my_object', $aData);
    // saving data to cache server
    $oCache->setData('our_class_object', $oCache);
    // saving object of our class into cache server too
    echo 'Now we saved all in cache server, click <a href="index2.php">here</a> to check what we have in cache server';
} else {
    echo 'Seems Memcache not installed, please install it to perform tests';
}
    public function postProcess()
    {
        /* PrestaShop demo mode */
        if (_PS_MODE_DEMO_) {
            $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error');
            return;
        }
        Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'Before', array('controller' => $this));
        if (Tools::isSubmit('submitAddServer')) {
            if ($this->access('add')) {
                if (!Tools::getValue('memcachedIp')) {
                    $this->errors[] = $this->trans('The Memcached IP is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!Tools::getValue('memcachedPort')) {
                    $this->errors[] = $this->trans('The Memcached port is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!Tools::getValue('memcachedWeight')) {
                    $this->errors[] = $this->trans('The Memcached weight is missing.', array(), 'Admin.Parameters.Notification');
                }
                if (!count($this->errors)) {
                    if (CacheMemcache::addServer(pSQL(Tools::getValue('memcachedIp')), (int) Tools::getValue('memcachedPort'), (int) Tools::getValue('memcachedWeight'))) {
                        Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                    } else {
                        $this->errors[] = $this->trans('The Memcached server cannot be added.', array(), 'Admin.Parameters.Notification');
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to add this.', array(), 'Admin.Notifications.Error');
            }
        }
        if (Tools::getValue('deleteMemcachedServer')) {
            if ($this->access('add')) {
                if (CacheMemcache::deleteServer((int) Tools::getValue('deleteMemcachedServer'))) {
                    Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
                } else {
                    $this->errors[] = $this->trans('There was an error when attempting to delete the Memcached server.', array(), 'Admin.Parameters.Notification');
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to delete this.', array(), 'Admin.Notifications.Error');
            }
        }
        $redirectAdmin = false;
        if ((bool) Tools::getValue('smarty_up')) {
            if ($this->access('edit')) {
                Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
                if (Configuration::get('PS_SMARTY_CACHE') != Tools::getValue('smarty_cache')) {
                    Tools::clearSmartyCache();
                }
                Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
                Configuration::updateValue('PS_SMARTY_CLEAR_CACHE', Tools::getValue('smarty_clear_cache'));
                Configuration::updateValue('PS_SMARTY_LOCAL', Tools::getValue('smarty_local', 0));
                $redirectAdmin = true;
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('features_detachables_up')) {
            if ($this->access('edit')) {
                if (Tools::isSubmit('combination')) {
                    if ((!Tools::getValue('combination') && Combination::isCurrentlyUsed()) === false) {
                        Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', (bool) Tools::getValue('combination'));
                    }
                }
                if (Tools::isSubmit('customer_group')) {
                    if ((!Tools::getValue('customer_group') && Group::isCurrentlyUsed()) === false) {
                        Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', (bool) Tools::getValue('customer_group'));
                    }
                }
                Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', (bool) Tools::getValue('feature'));
                $redirectAdmin = true;
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('ccc_up')) {
            if ($this->access('edit')) {
                $theme_cache_directory = _PS_ALL_THEMES_DIR_ . $this->context->shop->theme_directory . '/cache/';
                @mkdir($theme_cache_directory, 0777, true);
                if (((bool) Tools::getValue('PS_CSS_THEME_CACHE') || (bool) Tools::getValue('PS_JS_THEME_CACHE')) && !is_writable($theme_cache_directory)) {
                    $this->errors[] = $this->trans('To use Smart Cache, the directory %directorypath% must be writable.', array('%directorypath%' => realpath($theme_cache_directory)), 'Admin.Parameters.Notification');
                }
                if ($tmp = (int) Tools::getValue('PS_CSS_THEME_CACHE')) {
                    $version = (int) Configuration::get('PS_CCCCSS_VERSION');
                    if (Configuration::get('PS_CSS_THEME_CACHE') != $tmp) {
                        Configuration::updateValue('PS_CCCCSS_VERSION', ++$version);
                    }
                }
                if ($tmp = (int) Tools::getValue('PS_JS_THEME_CACHE')) {
                    $version = (int) Configuration::get('PS_CCCJS_VERSION');
                    if (Configuration::get('PS_JS_THEME_CACHE') != $tmp) {
                        Configuration::updateValue('PS_CCCJS_VERSION', ++$version);
                    }
                }
                if (!Configuration::updateValue('PS_CSS_THEME_CACHE', (int) Tools::getValue('PS_CSS_THEME_CACHE')) || !Configuration::updateValue('PS_JS_THEME_CACHE', (int) Tools::getValue('PS_JS_THEME_CACHE')) || !Configuration::updateValue('PS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_HTML_THEME_COMPRESSION', (int) Tools::getValue('PS_JS_HTML_THEME_COMPRESSION')) || !Configuration::updateValue('PS_JS_DEFER', (int) Tools::getValue('PS_JS_DEFER')) || !Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int) Tools::getValue('PS_HTACCESS_CACHE_CONTROL'))) {
                    $this->errors[] = $this->trans('Unknown error.', array(), 'Admin.Notifications.Error');
                } else {
                    $redirectAdmin = true;
                    if (Configuration::get('PS_HTACCESS_CACHE_CONTROL')) {
                        if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) {
                            Tools::generateHtaccess();
                        } else {
                            $message = $this->l('Before being able to use this tool, you need to:');
                            $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.');
                            $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).');
                            $this->errors[] = Tools::displayError($message, false);
                            Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
                        }
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('media_server_up') && !defined('_PS_HOST_MODE_')) {
            if ($this->access('edit')) {
                if (Tools::getValue('_MEDIA_SERVER_1_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_1_'))) {
                    $this->errors[] = $this->trans('Media server #1 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (Tools::getValue('_MEDIA_SERVER_2_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_2_'))) {
                    $this->errors[] = $this->trans('Media server #2 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (Tools::getValue('_MEDIA_SERVER_3_') != null && !Validate::isFileName(Tools::getValue('_MEDIA_SERVER_3_'))) {
                    $this->errors[] = $this->trans('Media server #3 is invalid', array(), 'Admin.Parameters.Notification');
                }
                if (!count($this->errors)) {
                    $base_urls = array();
                    $base_urls['_MEDIA_SERVER_1_'] = Tools::getValue('_MEDIA_SERVER_1_');
                    $base_urls['_MEDIA_SERVER_2_'] = Tools::getValue('_MEDIA_SERVER_2_');
                    $base_urls['_MEDIA_SERVER_3_'] = Tools::getValue('_MEDIA_SERVER_3_');
                    if ($base_urls['_MEDIA_SERVER_1_'] || $base_urls['_MEDIA_SERVER_2_'] || $base_urls['_MEDIA_SERVER_3_']) {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 1);
                    } else {
                        Configuration::updateValue('PS_MEDIA_SERVERS', 0);
                    }
                    rewriteSettingsFile($base_urls, null, null);
                    Configuration::updateValue('PS_MEDIA_SERVER_1', Tools::getValue('_MEDIA_SERVER_1_'));
                    Configuration::updateValue('PS_MEDIA_SERVER_2', Tools::getValue('_MEDIA_SERVER_2_'));
                    Configuration::updateValue('PS_MEDIA_SERVER_3', Tools::getValue('_MEDIA_SERVER_3_'));
                    Tools::clearSmartyCache();
                    Media::clearCache();
                    if (is_writable(_PS_ROOT_DIR_ . '/.htaccess')) {
                        Tools::generateHtaccess(null, null, null, '', null, array($base_urls['_MEDIA_SERVER_1_'], $base_urls['_MEDIA_SERVER_2_'], $base_urls['_MEDIA_SERVER_3_']));
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_1_']);
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_2_']);
                        unset($this->_fieldsGeneral['_MEDIA_SERVER_3_']);
                        $redirectAdmin = true;
                    } else {
                        $message = $this->l('Before being able to use this tool, you need to:');
                        $message .= '<br />- ' . $this->l('Create a blank .htaccess in your root directory.');
                        $message .= '<br />- ' . $this->l('Give it write permissions (CHMOD 666 on Unix system).');
                        $this->errors[] = Tools::displayError($message, false);
                        Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', false);
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('cache_up')) {
            if ($this->access('edit')) {
                $config = Yaml::parse(_PS_ROOT_DIR_ . '/app/config/parameters.yml');
                $cache_active = (bool) Tools::getValue('cache_active');
                if ($caching_system = preg_replace('[^a-zA-Z0-9]', '', Tools::getValue('caching_system'))) {
                    $config['parameters']['ps_caching'] = $caching_system;
                } else {
                    $cache_active = false;
                    $this->errors[] = $this->trans('The caching system is missing.', array(), 'Admin.Parameters.Notification');
                }
                if ($cache_active) {
                    if ($caching_system == 'CacheMemcache' && !extension_loaded('memcache')) {
                        $this->errors[] = $this->trans('To use Memcached, you must install the Memcache PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://www.php.net/manual/en/memcache.installation.php">http://www.php.net/manual/en/memcache.installation.php</a>';
                    } elseif ($caching_system == 'CacheMemcached' && !extension_loaded('memcached')) {
                        $this->errors[] = $this->trans('To use Memcached, you must install the Memcached PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://www.php.net/manual/en/memcached.installation.php">http://www.php.net/manual/en/memcached.installation.php</a>';
                    } elseif ($caching_system == 'CacheApc' && !extension_loaded('apc') && !extension_loaded('apcu')) {
                        $this->errors[] = $this->trans('To use APC cache, you must install the APC PECL extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://fr.php.net/manual/fr/apc.installation.php">http://fr.php.net/manual/fr/apc.installation.php</a>';
                    } elseif ($caching_system == 'CacheXcache' && !extension_loaded('xcache')) {
                        $this->errors[] = $this->trans('To use Xcache, you must install the Xcache extension on your server.', array(), 'Admin.Parameters.Notification') . '
							<a href="http://xcache.lighttpd.net">http://xcache.lighttpd.net</a>';
                    } elseif ($caching_system == 'CacheXcache' && !ini_get('xcache.var_size')) {
                        $this->errors[] = $this->trans('To use Xcache, you must configure "xcache.var_size" for the Xcache extension (recommended value 16M to 64M).', array(), 'Admin.Parameters.Notification') . '
							<a href="http://xcache.lighttpd.net/wiki/XcacheIni">http://xcache.lighttpd.net/wiki/XcacheIni</a>';
                    } elseif ($caching_system == 'CacheFs') {
                        if (!is_dir(_PS_CACHEFS_DIRECTORY_)) {
                            @mkdir(_PS_CACHEFS_DIRECTORY_, 0777, true);
                        } elseif (!is_writable(_PS_CACHEFS_DIRECTORY_)) {
                            $this->errors[] = $this->trans('To use CacheFS, the directory %directorypath% must be writable.', array('%directorypath%' => realpath(_PS_CACHEFS_DIRECTORY_)), 'Admin.Parameters.Notification');
                        }
                    }
                    if ($caching_system == 'CacheFs') {
                        if (!($depth = Tools::getValue('ps_cache_fs_directory_depth'))) {
                            $this->errors[] = $this->trans('Please set a directory depth.', array(), 'Admin.Parameters.Notification');
                        }
                        if (!count($this->errors)) {
                            CacheFs::deleteCacheDirectory();
                            CacheFs::createCacheDirectories((int) $depth);
                            Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', (int) $depth);
                        }
                    } elseif ($caching_system == 'CacheMemcache' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache') {
                        Cache::getInstance()->flush();
                    } elseif ($caching_system == 'CacheMemcached' && !_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcached') {
                        Cache::getInstance()->flush();
                    }
                }
                if (!count($this->errors)) {
                    $config['parameters']['ps_cache_enable'] = $cache_active;
                    // If there is not settings file modification or if the backup and replacement of the settings file worked
                    if (file_put_contents(_PS_ROOT_DIR_ . '/app/config/parameters.yml', Yaml::dump($config))) {
                        if (function_exists('opcache_invalidate')) {
                            opcache_invalidate(_PS_ROOT_DIR_ . '/app/config/parameters.yml');
                        }
                        $redirectAdmin = true;
                    } else {
                        $this->errors[] = $this->trans('The settings file cannot be overwritten.', array(), 'Admin.Parameters.Notification');
                    }
                }
            } else {
                $this->errors[] = $this->trans('You do not have permission to edit this.', array(), 'Admin.Notifications.Error');
            }
        }
        if ((bool) Tools::getValue('empty_smarty_cache')) {
            $redirectAdmin = true;
            Tools::clearSmartyCache();
            Tools::clearXMLCache();
            Media::clearCache();
            Tools::generateIndex();
        }
        if ((bool) Tools::getValue('empty_sf2_cache')) {
            $redirectAdmin = true;
            $sf2Refresh = new \PrestaShopBundle\Service\Cache\Refresh();
            $sf2Refresh->addCacheClear(_PS_MODE_DEV_ ? 'dev' : 'prod');
            $sf2Refresh->execute();
        }
        if (Tools::isSubmit('submitAddconfiguration')) {
            Configuration::updateGlobalValue('PS_DISABLE_NON_NATIVE_MODULE', (int) Tools::getValue('native_module'));
            Configuration::updateGlobalValue('PS_DISABLE_OVERRIDES', (int) Tools::getValue('overrides'));
            if (Tools::isSubmit('debug_mode') && (bool) Tools::getValue('debug_mode')) {
                $debug_mode_status = $this->enableDebugMode();
            } else {
                $debug_mode_status = $this->disableDebugMode();
            }
            if (!empty($debug_mode_status)) {
                switch ($debug_mode_status) {
                    case self::DEBUG_MODE_ERROR_COULD_NOT_BACKUP:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.old.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_DEFINITION_FOUND:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not find whether debug mode is enabled. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS_CUSTOM:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not write to file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines_custom.inc.php'));
                        break;
                    case self::DEBUG_MODE_ERROR_NO_READ_ACCESS:
                        $this->errors[] = Tools::displayError(sprintf($this->l('Error: could not read file. Make sure that the correct permissions are set on the file %s'), _PS_ROOT_DIR_ . '/config/defines.inc.php'));
                        break;
                    default:
                        break;
                }
            }
            Tools::generateIndex();
        }
        if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) {
            Hook::exec('action' . get_class($this) . ucfirst($this->action) . 'After', array('controller' => $this, 'return' => ''));
            Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=4');
        }
    }
예제 #9
0
 /**
  * Returns a Memcache instance. Will try certain fallbacks to get a working implementation 
  * 
  * @return CacheInterface
  */
 public static function factory()
 {
     $memcached = new CacheMemcached();
     if ($memcached->supported()) {
         return $memcached;
     } else {
         $fallback = new CacheMemcache();
         if ($fallback->supported()) {
             return $fallback;
         }
     }
     throw new Exception('Missing memcached php-extension');
 }
예제 #10
0
 /**
  * Удаление значения из кэша.
  * @param $key
  * @return bool
  */
 public static function delete($key)
 {
     unset(self::$storage_arr[$key]);
     return CacheMemcache::delete($key);
 }
예제 #11
0
<?php

define('IN_TIPASK', TRUE);
define('TIPASK_ROOT', substr(dirname(__FILE__), 0, -4));
date_default_timezone_set('Etc/GMT-8');
// 普通的 http 通知方式
error_reporting(0);
require_once TIPASK_ROOT . '/config.php';
require_once TIPASK_ROOT . '/lib/db.class.php';
require_once TIPASK_ROOT . '/lib/global.func.php';
require_once TIPASK_ROOT . '/lib/CacheMemcache.class.php';
$db = new db(DB_HOST, DB_USER, DB_PW, DB_NAME, DB_CHARSET, DB_CONNECT);
$memcache = new CacheMemcache();
$setting = $memcache->load('setting');
$ts_warn_maxNum = isset($setting['ts_warn_maxNum']) ? $setting['ts_warn_maxNum'] : 3;
// 投诉同步失败报警最大数量,默认3
$ts_warn_num = isset($setting['ts_warn_num']) ? $setting['ts_warn_num'] : 0;
// 投诉同步失败报警阈值:
$ts_warn_time = isset($setting['ts_warn_time']) ? $setting['ts_warn_time'] : 0;
// 投诉同步失败报警时间间隔 ,不填就是 所有
if ($ts_warn_time != 0) {
    $timeRang = time() - $ts_warn_time;
    $where .= " AND time > {$timeRang}";
}
$sql = "SELECT count(id) FROM ask_complain WHERE sync <= -{$ts_warn_num} {$where}";
$num = $db->result_first($sql);
echo $sql . '<br>ts_warn_maxNum = ' . $setting['ts_warn_maxNum'] . '<br>' . 'ts_warn_time = ' . $setting['ts_warn_time'] . '<br>' . 'ts_warn_num = ' . $setting['ts_warn_num'] . '<br>';
if (!empty($num)) {
    if ($num >= $ts_warn_maxNum) {
        if ($ts_warn_time != 0) {
            $warm_message = "{$ts_warn_time} 秒内 投诉失败数量:{$num} 报警";
예제 #12
0
<?php

require_once 'memcache.caching.php';
$oCache = new CacheMemcache();
if ($oCache->bEnabled) {
    // if Memcache enabled
    $aMemData = $oCache->getData('my_object');
    // getting data from cache server
    $aMemData2 = $oCache->getData('our_class_object');
    // getting data from cache server about our class
    echo 'Data from cache server: <pre>';
    // lets see what we have from cache server
    print_r($aMemData);
    echo '</pre>';
    echo 'Data from cache server of object of CacheMemcache class: <pre>';
    print_r($aMemData2);
    echo '</pre>';
    echo 'As you can see - all data read successfully, now lets remove data from cache server and check results, click <a href="index3.php">here</a> to continue';
} else {
    echo 'Seems Memcache not installed, please install it to perform tests';
}
예제 #13
0
defined('MAGIC_QUOTES_GPC') || define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
require_once TIPASK_ROOT . '/config.php';
require TIPASK_ROOT . '/model/base.class.php';
require TIPASK_ROOT . '/lib/config.class.php';
require TIPASK_ROOT . '/lib/db.class.php';
require TIPASK_ROOT . '/lib/pdo/Mysql/pdo.class.php';
require TIPASK_ROOT . '/lib/pdo/Mysql/hash.class.php';
require_once TIPASK_ROOT . '/lib/global.func.php';
require_once TIPASK_ROOT . '/lib/CacheMemcache.class.php';
//require_once TIPASK_ROOT.'/lib/CacheRedis.class.php';
$table = array('table_question' => "ask_question", 'table_complain' => "ask_complain");
$returnArray = array('suggest' => array(), 'ask' => array(), 'complain' => array());
$type = trim($_GET['type']) == "new" ? "new" : "old";
$count = intval($_GET['count']) > 0 ? intval($_GET['count']) : 10;
$qtype = intval($_GET['qtype']) > 0 ? intval($_GET['qtype']) : 0;
$memcache = new CacheMemcache();
$base = new base();
$pdo = $base->init_pdo($table['table_question']);
$base->load('question');
$base->load('qtype');
$base->load('answer');
$base->load('category');
$base->load('complain');
$q = $memcache->get('newqtype_list');
if (false !== $q) {
    $qtypeList = json_decode($q, true);
} else {
    $qtypeList = $_ENV['qtype']->GetAllQType(1, "", 0);
    $memcache->set('qtype_list', json_encode($qtypeList), 30 * 60);
    //缓存60秒
}