zoukankan      html  css  js  c++  java
  • 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的功能要多。

    不带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"
  • 相关阅读:
    转:wap1.1和wap2.0的比较~
    转:alidateRequest=false 在.Net 4.0 中不管用
    ASP.NET页面实时进行GZIP压缩优化
    转:WAP1.0 和 WAP2.0 支持的标签区别
    [转载]利用vs.net快速开发windows服务(c#)
    CSS3选择器
    AD10 多层板设计错误解决
    ASP如何获取客户端真实IP地址
    javascript模拟滚动条实现代码(3)
    最近工作中的小细节
  • 原文地址:https://www.cnblogs.com/-mrl/p/13285032.html
Copyright © 2011-2022 走看看