PHP似乎有两个memcached库,分别命名为memcache和memcached。有什么不同,你如何知道使用哪一个?一个过时了吗?memcached似乎提供了更多的方法,所以我认为这意味着它已经有了最多的开发-但它似乎也需要外部C/ c++库,所以我不确定我是否可以安装它。
memcache似乎已经存在了很长时间,它不需要额外的库,甚至还为windows提供了预编译的二进制文件!我认为这是目前更好的选择。然而,作为memcached(服务器)的新手,我不确定memcached (php)中是否有一些超级重要的特性值得额外的麻烦。
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 callbacks are 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.
所有这些点都足以让我切换到最新的客户端,并且可以告诉你它的工作就像一个魅力。libmemcached库有外部依赖,但是已经设法在Ubuntu和Mac OSX上安装了它,所以到目前为止没有问题。
如果您决定更新到更新的库,我建议您更新到最新的服务器版本,因为它也有一些不错的功能。你需要安装libevent来编译它,但是在Ubuntu上并不是很麻烦。
到目前为止,我还没有看到任何框架支持新的memcached客户机(尽管我没有跟踪它们),但我认为Zend很快就会加入进来。
更新
Zend Framework 2有一个Memcached的适配器,可以在这里找到