public function initFieldsetCaching() { $caching_system = array(0 => array('id' => 'CacheMemcache', 'name' => $this->l('Memcached')), 1 => array('id' => 'CacheApc', 'name' => $this->l('APC')), 2 => array('id' => 'CacheXcache', 'name' => $this->l('Xcache')), 3 => array('id' => 'CacheFs', 'name' => $this->l('File System'))); $this->fields_form[5]['form'] = array('legend' => array('title' => $this->l('Caching'), 'image' => '../img/admin/computer_key.png'), 'desc' => $this->l('Caching systems are used to speed up your store by caching data into the server\'s memory, avoiding the exhausting task of querying the database.'), 'input' => array(array('type' => 'hidden', 'name' => 'cache_up'), array('type' => 'radio', 'label' => $this->l('Use cache'), 'name' => 'active', 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Enable or disable caching system')), array('type' => 'select', 'label' => $this->l('Caching system'), 'name' => 'caching_system', 'options' => array('query' => $caching_system, 'id' => 'id', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Directory depth'), 'name' => 'ps_cache_fs_directory_depth', 'size' => 30)), 'submit' => array('title' => $this->l(' Save '), 'class' => 'button'), 'memcachedServers' => true); $depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH'); $this->fields_value['active'] = _PS_CACHE_ENABLED_; $this->fields_value['caching_system'] = _PS_CACHING_SYSTEM_; $this->fields_value['ps_cache_fs_directory_depth'] = $depth ? $depth : 1; $this->tpl_form_vars['servers'] = CacheMemcache::getMemcachedServers(); }
/** * 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; }
public function initFieldsetCaching() { $phpdoc_langs = array('en', 'zh', 'fr', 'de', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr'); $php_lang = in_array($this->context->language->iso_code, $phpdoc_langs) ? $this->context->language->iso_code : 'en'; $warning_memcached = ' ' . $this->l('(you must install the [a]Memcache PECL extension[/a])'); $warning_memcached = str_replace('[a]', '<a href="http://www.php.net/manual/' . substr($php_lang, 0, 2) . '/memcache.installation.php" target="_blank">', $warning_memcached); $warning_memcached = str_replace('[/a]', '</a>', $warning_memcached); $warning_apc = ' ' . $this->l('(you must install the [a]APC PECL extension[/a])'); $warning_apc = str_replace('[a]', '<a href="http://php.net/manual/' . substr($php_lang, 0, 2) . '/apc.installation.php" target="_blank">', $warning_apc); $warning_apc = str_replace('[/a]', '</a>', $warning_apc); $warning_xcache = ' ' . $this->l('(you must install the [a]Xcache extension[/a])'); $warning_xcache = str_replace('[a]', '<a href="http://xcache.lighttpd.net" target="_blank">', $warning_xcache); $warning_xcache = str_replace('[/a]', '</a>', $warning_xcache); $warning_fs = ' ' . sprintf($this->l('(the directory %s must be writable)'), realpath(_PS_CACHEFS_DIRECTORY_)); $this->fields_form[6]['form'] = array('legend' => array('title' => $this->l('Caching'), 'icon' => 'icon-desktop'), 'input' => array(array('type' => 'hidden', 'name' => 'cache_up'), array('type' => 'switch', 'label' => $this->l('Use cache'), 'name' => 'cache_active', 'is_bool' => true, 'values' => array(array('id' => 'cache_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'cache_active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'radio', 'label' => $this->l('Caching system'), 'name' => 'caching_system', 'hint' => $this->l('The CacheFS system should be used only when the infrastructure contains one front-end server. If you are not sure, ask your hosting company.'), 'values' => array(array('id' => 'CacheFs', 'value' => 'CacheFs', 'label' => $this->l('File System') . (is_writable(_PS_CACHEFS_DIRECTORY_) ? '' : $warning_fs)), array('id' => 'CacheMemcache', 'value' => 'CacheMemcache', 'label' => $this->l('Memcached') . (extension_loaded('memcache') ? '' : $warning_memcached)), array('id' => 'CacheApc', 'value' => 'CacheApc', 'label' => $this->l('APC') . (extension_loaded('apc') ? '' : $warning_apc)), array('id' => 'CacheXcache', 'value' => 'CacheXcache', 'label' => $this->l('Xcache') . (extension_loaded('xcache') ? '' : $warning_xcache)))), array('type' => 'text', 'label' => $this->l('Directory depth'), 'name' => 'ps_cache_fs_directory_depth')), 'submit' => array('title' => $this->l('Save')), 'memcachedServers' => true); $depth = Configuration::get('PS_CACHEFS_DIRECTORY_DEPTH'); $this->fields_value['cache_active'] = _PS_CACHE_ENABLED_; $this->fields_value['caching_system'] = _PS_CACHING_SYSTEM_; $this->fields_value['ps_cache_fs_directory_depth'] = $depth ? $depth : 1; $this->tpl_form_vars['servers'] = CacheMemcache::getMemcachedServers(); }
public function initContent() { $this->initTabModuleList(); $php_dot_net_supported_langs = array('en', 'zh', 'fr', 'de', 'ja', 'pl', 'ro', 'ru', 'fa', 'es', 'tr'); $php_lang = in_array($this->context->language->iso_code, $php_dot_net_supported_langs) ? $this->context->language->iso_code : 'en'; if (_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache' && !CacheMemcache::getMemcachedServers()) { $this->warnings[] = $this->l('To use Memcached, you must configure memcached servers.'); } if (_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'CacheMemcache' && !extension_loaded('memcache')) { $this->warnings[] = $this->l('To use Memcached, you must install the Memcache PECL extension on your server.') . ' <a href="http://www.php.net/manual/' . substr($php_lang, 0, 2) . '/memcache.installation.php" target="_blank"> http://www.php.net/manual/' . substr($php_lang, 0, 2) . '/memcache.installation.php </a>'; } if (_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'apc' && !extension_loaded('apc')) { $this->warnings[] = $this->l('To use APC, you must install the APC PECL extension on your server.') . ' <a href="http://php.net/manual/' . substr($php_lang, 0, 2) . '/apc.installation.php" target="_blank"> http://php.net/manual/' . substr($php_lang, 0, 2) . '/apc.installation.php </a>'; } if (_PS_CACHE_ENABLED_ && _PS_CACHING_SYSTEM_ == 'xcache' && !extension_loaded('xcache')) { $this->warnings[] = $this->l('To use Xcache, you must install the Xcache extension on your server.') . ' <a href="http://xcache.lighttpd.net" target="_blank">http://xcache.lighttpd.net</a>'; } if (!is_writable(_PS_CACHEFS_DIRECTORY_)) { $this->warnings[] = sprintf($this->l('To use the CacheFS directory %s must be writable.'), realpath(_PS_CACHEFS_DIRECTORY_)); } $this->initToolbar(); $this->display = ''; $this->content .= $this->renderForm(); $this->context->smarty->assign(array('content' => $this->content, 'url_post' => self::$currentIndex . '&token=' . $this->token)); }