php 如何在 Joomla 中使用 memcached
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1260258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use memcached with Joomla
提问by webkul
How can I use memcache in Joomla? I'm a newbie in this field so please be descriptive with your answer.
如何在 Joomla 中使用内存缓存?我是这个领域的新手,所以请描述你的答案。
回答by jlleblanc
You will need to install memcached on your server and will probably need root access to do so. You can get memcached from http://www.danga.com/memcached/. It requires libevent, which can be downloaded here: http://www.monkey.org/~provos/libevent/
您需要在服务器上安装 memcached,并且可能需要 root 访问权限才能这样做。您可以从http://www.danga.com/memcached/获取 memcached 。它需要 libevent,可以在这里下载:http: //www.monkey.org/~provos/libevent/
Finally, you'll need to get the PHP PECL extension for memcache. To install this, you need to go to the server where PHP is installed and run this command:
最后,您需要为 memcache 获取 PHP PECL 扩展。要安装它,您需要转到安装 PHP 的服务器并运行以下命令:
pecl install memcache
Again, you will most likely need root access to your server to do this. After you have libevent, memcached, and the PECL extensions installed, go to the Global Configuration in Joomla and choose Memory Cacheas the Cache Handler under Cache Settings. After you save the Global Configuration, open it again and more inputs should appear underneath the Cache Handler input. Set Memory Chache Server to localhostand the port to 11211. This should match the parameters you use to run memcachedfrom the command line.
同样,您很可能需要对服务器的 root 访问权限才能执行此操作。在安装了 libevent、memcached 和 PECL 扩展后,转到 Joomla 中的全局配置并Memory Cache在缓存设置下选择缓存处理程序。保存全局配置后,再次打开它,缓存处理程序输入下方应该会出现更多输入。将 Memory Chache Server 设置为localhost,将端口设置为11211。这应该与您用于从命令行运行的参数相匹配memcached。
EDIT: You can also use XCache not only to store data in a way similar to Memcache, but it will also cache the opcode generated by PHP. This way, instead of reading the PHP code from disk and parsing it each time, it will hold the code in memory for the next request.
编辑:您还可以使用 XCache 不仅以类似于 Memcache 的方式存储数据,而且还将缓存 PHP 生成的操作码。这样,它不会从磁盘读取 PHP 代码并每次都解析它,而是将代码保存在内存中以备下一次请求。
Be sure to select XCacheas the Cache Handler in Global Configuration. Read this for information on installing XCache: http://xcache.lighttpd.net/wiki/InstallFromSource
确保XCache在全局配置中选择为缓存处理程序。阅读有关安装 XCache 的信息:http: //xcache.lighttpd.net/wiki/InstallFromSource
回答by Marian HackMan Marinov
In order to make Joomla to use memcache for session caching you need to manually edit the configuration.php and change this line:
为了让 Joomla 使用 memcache 进行会话缓存,您需要手动编辑 configuration.php 并更改此行:
public $session_handler = 'database';
to this one:
对这个:
public $session_handler = 'memcache';
And this is what is missing everywhere, you need to add a new option memcache_settings:
这就是到处都缺少的东西,您需要添加一个新选项 memcache_settings:
public $memcache_settings = 'a:3:{s:10:"persistent";s:1:"0";s:11:"compression";s:1:"0";s:7:"servers";a:1:{i:0;a:2:{s:4:"host";s:9:"127.0.0.1";s:4:"port";s:5:"11211";}}}';
This is a serialized multy-dimentianal array. I use this code to generate the above string:
这是一个序列化的多维数组。我使用此代码生成上述字符串:
$a = array(
"persistent" => "0",
"compression" => "0",
"servers" => array(
"0" => array(
"host" => "127.0.0.1", "port" => "11211")
)
);
echo(serialize($a));
If you don't add the memcache_settings option your sessions will never work with memcache.
如果您不添加 memcache_settings 选项,您的会话将永远不会与 memcache 一起使用。
回答by Stuart Cardall
These settings in configuration.phpwork for memcachedin Joomla 3.3+
这些设置configuration.php适用memcached于 Joomla 3.3+
public $cache_handler = 'memcached';
public $memcached_server_host = '127.0.0.1';
public $memcached_server_port = '11211';
public $memcached_persist = '1';
public $memcached_compress = '1';
public $cachetime = '15';
public $session_handler = 'memcached';
public $session_memcached_server_host = '127.0.0.1';
public $session_memcached_server_port = '11211';
To install memcachedon a Debian system:
memcached在 Debian 系统上安装:
apt-get install memcached php5-memcached
(you can also use memcachein place of each occurence of memcachedin the above publicvariables & install the older php5-memcacheextension)
(您也可以使用memcache代替memcached上述public变量中的每次出现并安装旧php5-memcache扩展)
Upgrading to php5.5will give you a builtin Zend Opcode Cache- this could be used with APCu(APCuis the Alternative PHP Cachewith the Opcode Cache removed) - to cache userland locally if you do not need a distributed memory cache (memcached)
升级到php5.5将为您提供一个内置的Zend Opcode 缓存- 这可以与APCu一起使用 (APCu是移除了 Opcode 缓存的替代 PHP 缓存)- 如果您不需要分布式内存缓存,则可以在本地缓存用户空间 ( )memcached
For a single VPS APCuhas a lower memory footprint & is a more suitable cache (especially with php5.5) & can be set in configuration.phpwith:
对于单个 VPS APCu具有较低的内存占用 & 是一个更合适的缓存 (尤其是php5.5) & 可以设置configuration.php为:
public $cache_handler = 'apc';
public $session_handler = 'apc';
回答by tristanbailey
This how to might also offer some help for Joomla 2.5 as it points to the Joomla Admin Screen to use memcache http://www.siteground.com/tutorials/supercacher/joomla_memcached.htm
这个方法也可能为 Joomla 2.5 提供一些帮助,因为它指向 Joomla 管理屏幕以使用 memcache http://www.siteground.com/tutorials/supercacher/joomla_memcached.htm
回答by Joost van der Laan
It's better to not useAPC for backend cache. This can cause a lot of fragmentation. I have only seen it degrade performance of Joomla.
最好不要将APC 用于后端缓存。这会导致很多碎片。我只看到它降低了 Joomla 的性能。

