ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP扩展memcache和memcached的区别

2020-07-11 19:03:54  阅读:289  来源: 互联网

标签:extension memcached memcache session PHP 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的功能要多。

不带d的memcache版本,这个版本出的比较早,是一个原生版本,完全在php框架内开发的。与之对应的带d的memcached是建立在libmemcached的基础上,所以相对来说,memcached版本的功能更全一些。 

两个都支持一致性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"

标签:extension,memcached,memcache,session,PHP,Memcached
来源: https://www.cnblogs.com/-mrl/p/13285032.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有