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"
  • 相关阅读:
    第三届NSCTF之easy ssrf
    第三届NSCTF测试题Welcome
    第三届NSCTF测试题Code php 之MD5碰撞和php strcmp函数绕过
    PUT方法提交message
    使用John the Ripper破解sha512加密的shadow文件密码
    第2章 SQL注入攻击:课时1:注入攻击原理及自己编写一个注入点
    配置IIS10支持php语言脚本
    身边的base64解码工具
    什么是JWT
    IDEA 远程调试
  • 原文地址:https://www.cnblogs.com/-mrl/p/13285032.html
Copyright © 2011-2022 走看看