php 我什么时候应该使用 Memcache 而不是 Memcached?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1442411/
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
When should I use Memcache instead of Memcached?
提问by Xeoncross
It seems that PHP has two memcached libraries named memcacheand memcached. What is the difference and how do you know which one to use? Is one outdated? It seems that memcached offers more methods so I would assume that means it has had the most development - but it also seems to require external C/C++ librariesso I'm not sure if I can install it.
PHP 似乎有两个名为memcache和memcached 的memcached 库。有什么区别,您如何知道使用哪一个?一个过时了吗?似乎 memcached 提供了更多方法,所以我认为这意味着它的开发最多 - 但它似乎也需要外部 C/C++ 库,所以我不确定是否可以安装它。
It seems that memcache has been around longer, does not require additional libraries, and has pre-compiled binariesfor even windows! I would think that it would be the better choice for now. However, being new to memcached (server) I'm not sure if there is some super important features in memcached (php) that make it worth the extra trouble.
似乎 memcache 已经存在的时间更长了,不需要额外的库,甚至为 Windows也有预编译的二进制文件!我认为这将是目前更好的选择。但是,作为 memcached(服务器)的新手,我不确定 memcached(php)中是否有一些非常重要的功能值得额外的麻烦。
采纳答案by Miha Hribar
Memcached clientlibrary was just recently released as stable. It is being used by digg( was developed for digg by Andrei Zmievski, now no longer with digg) and implements much more of the memcached protocolthan the older memcache client. The most important features that memcached has are:
Memcached 客户端库最近刚刚发布稳定版。它正在被digg 使用(由 Andrei Zmievski 为 digg 开发,现在不再与 digg 一起使用)并且比旧的 memcache 客户端实现了更多的memcached 协议。memcached 最重要的特性是:
- Cas tokens. This made my life much easier and is an easy preventive system for stale data. Whenever you pull something from the cache, you can receive with it a cas token (a double number). You can than use that token to save your updated object. If no one else updated the value while your thread was running, the swap will succeed. Otherwise a newer cas token was created and you are forced to reload the data and save it again with the new token.
- Read through callbacksare the best thing since sliced bread. It has simplified much of my code.
- getDelayed()is a nice feature that can reduce the time your script has to wait for the results to come back from the server.
- While the memcached server is supposed to be very stable, it is not the fastest. You can use binary protocol instead of ASCII with the newer client.
- Whenever you save complex data into memcached the client used to always do serialization of the value (which is slow), but now with memcached client you have the option of using igbinary. So far I haven't had the chance to test how much of a performance gain this can be.
- Cas 令牌。这让我的生活变得更轻松,并且是一个简单的陈旧数据预防系统。每当您从缓存中提取某些内容时,您都会收到一个 cas 令牌(双数)。您可以使用该令牌来保存更新的对象。如果在您的线程运行时没有其他人更新该值,则交换将成功。否则会创建一个较新的 cas 令牌,您将被迫重新加载数据并使用新令牌再次保存。
- 通读回调是自切片面包以来最好的事情。它简化了我的大部分代码。
- getDelayed()是一个很好的功能,可以减少脚本等待结果从服务器返回的时间。
- 虽然 memcached 服务器应该非常稳定,但它并不是最快的。对于较新的客户端,您可以使用二进制协议而不是 ASCII。
- 每当您将复杂数据保存到 memcached 中时,客户端过去总是对值进行序列化(这很慢),但现在使用 memcached 客户端,您可以选择使用igbinary。到目前为止,我还没有机会测试这可以带来多少性能提升。
All of this points were enough for me to switch to the newest client, and can tell you that it works like a charm. There is that external dependency on the libmemcachedlibrary, but have managed to install it nonetheless on Ubuntu and Mac OSX, so no problems there so far.
所有这些点都足以让我切换到最新的客户端,并且可以告诉您它的效果非常好。对libmemcached库有外部依赖,但仍然设法在 Ubuntu 和 Mac OSX 上安装它,所以到目前为止没有问题。
If you decide to update to the newer library, I suggest you update to the latest server version as well as it has some nice features as well. You will need to install libeventfor it to compile, but on Ubuntu it wasn't much trouble.
如果您决定更新到较新的库,我建议您更新到最新的服务器版本,因为它也有一些不错的功能。您需要安装libevent才能进行编译,但在 Ubuntu 上这并不麻烦。
I haven't seen any frameworks pick up the new memcached client thus far (although I don't keep track of them), but I presume Zendwill get on board shortly.
到目前为止,我还没有看到任何框架采用新的 memcached 客户端(虽然我没有跟踪它们),但我认为Zend很快就会加入。
UPDATE
更新
Zend Framework 2 has an adapter for Memcached which can be found here
Zend Framework 2 有一个适用于 Memcached 的适配器,可以在这里找到
回答by rymo
When using Windows, the comparison is cut short: memcacheappears to be the only client available.
使用 Windows 时,比较被缩短:memcache似乎是唯一可用的客户端。
回答by Mike Trest
This is 2013. Forget about the 2009 comments. Likewise, if you are running serious traffic loads, do not even contemplate how to make-do with a windows based memcache. When dealing with a very large scale (500+ front end web servers) and 20+ back end database servers and replicants (mysql & mssql mix), a farm of memcached servers (12 servers in group) supports multiple high volume OLTP applications answering 25K ~ 40K mc->get calls per-second. These calls are those that do NOThave to reach a database.
这是 2013 年。忘记 2009 年的评论。同样,如果您正在运行严重的流量负载,甚至不要考虑如何使用基于 Windows 的内存缓存。在处理超大规模(500 多个前端 Web 服务器)和 20 多个后端数据库服务器和复制程序(mysql 和 mssql 混合)时,memcached 服务器群(组中 12 个服务器)支持多个大容量 OLTP 应用程序,响应 25K ~ 40K mc->每秒调用。这些电话是指那些不具备到达数据库。
IMHO, this use of memcached provided SERIOUS $$$,$$$savings on CAPEX for new DB servers & licences as well as on support contracts for large commercial designs.
恕我直言,memcached 的这种使用为新的数据库服务器和许可证以及大型商业设计的支持合同提供了 CAPEX 的大量节省。
回答by RageZ
Memcached is a newer API, it also provides memcached as a session provider which could be great if you have a farm of server.
Memcached 是一个较新的 API,它还提供 memcached 作为会话提供程序,如果您有服务器群,这可能会很棒。
After the version is still really low 0.2 but I have used both and I didn't encounter major problem, so I would go to memcached since it's new.
0.2之后的版本还是很低,但是我两个都用过,没有遇到大问题,所以我会去memcached,因为它是新的。

