关于PHP扩展memcache和memcached的区别

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信。

PHP的客户端目前常用的有两个,一个是memcache,另一个是memcached,两个客户端只差了一个字母,这两个的区别是什么呢?

  • 服务器中的memcached进程跑的是memcached服务;
  • 实现了memcached接口的PHP扩展memcache,在PHP框架之内实现的;
  • 实现了memcached接口的PHP扩展memcached,基于libmemcached实现;

手册是最好的说明(大家没事还是多看看官方说明吧):
memcached
memcached类官方说明
memcached扩展包

memcache
memcache类官方说明
memcache扩展包

下面是PHP官网给予的相应解释
For those confuse about the memcached extension and the memcache extension, the short story is that both of them are clients of memcached server, and the memcached extension offer more features than the memcache extension.

大致意思是memcached extension和memcache extension都是memcached server的客户端,memcached extension比memcache extension的功能要多。

两个都支持一致性hash算法:

  • memcache
# 修改php.ini
[Memcache]
Memcache.allow_failover = 1 
Memcache.hash_strategy = consistent
Memcache.hash_function = crc32
  • memcached
$memcachedObj = new memcached();
$memcachedObj->setOption(Memcached::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
$memcachedObj->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true); 

另外说一下session在memcached(注意这个是指memcached服务)中的存储,下面是配置

# memcache:
session.save_handler = memcache
session.save_path = "tcp://localhost:11211" 
# memcached:
session.save_handler = memcached
session.save_path = "localhost:11211"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值