memcached

简介:

  Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

  Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

     memcache是一个高性能的分布式的内存对象缓存系统,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等

安装配置:

一、安装

1、Memcache Win32 的安装和PHP中的配置
1、解压到目录:c:mem (自定义,任何目录)
2、c:memmemcached.exe -d install
3、c:memmemcached.exe -d start (启动服务)
4、telnet 127.0.0.1 11211 (使用telnet连接测试是否成功)
5、输入:stats 命令查看基本信息

二、PHP中配置 Memcache
1、下载:php_memcache.dll 组件 (WAMP自带了)
  带VC6的php_memcache.dll :http://www.tjinfo.com.cn/down/php_memcache_VC6.zip
  带VC9的php_memcache.dll :http://downloads.php.net/pierre/
2、复制 php_memcache.dll 到指定的组件目录,默认在 phpext
3、在PHP.ini 加入一句话:extension=php_memcache.dll
4、重启WEB服务,使用 phpinfo() 函数查看启用情况
其它配置(在php.ini里):
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211

容易出现的问题:当重启wamp的时候容易出现问题,如:
PHP Warning:  PHP Startup: memcache: Unable to initialize module Module compiled with module API=20060613 PHP    compiled with module API=20090626 These options need to match in Unknown on line 0 PHP Warning:  PHP Startup: memcache: Unable to initialize module Module compiled with module API=20060613 PHP    compiled with module API=20090626 These options need to match in Unknown on line 0 bogus test name tests/

原因主要是用VC6编译的PHP和用VC9编译的php_memcache.dll不匹配,重新下载一个VC6编译的即可。
附加:PHP源码经过编译后, 有几个需要注意的地方:  编译器, 线程安全,  调试,  版本
编译器指编译时使用的编译器.
线程安全指是否开启了PHP的线程安全层.
调试指是否开启了PHP调试模式.
Module compiled with build ID=API20090626,TS,VC6
PHP compiled with build ID=API20090626,TS,VC9
这两句是说:
模块使用了20090626发行版的php构建工具, 开启线程安全, 未启用调试模式, 编译器为VC6
PHP使用了20090626发行版的php构建工具, 开启线程安全, 未启用调试模式, 编译器为VC9
所以, 你的问题在于两者使用了不同的编译器编译了.
因此, 你需要用VC9以线程安全非调试模式重新编译一下你的memcache模块. 或者你从网上找别人编译好的

三、PHP中测试 Memcache功能
$mem = new Memcache;
$mem->connect('127.0.0.1', 11211) or die ("连接失败");
$mem->getVersion();

原文地址:https://www.cnblogs.com/thinksasa/p/3419860.html