您的位置:首页 > 数据库 > Memcache

win7下64位系统memcache/memcached安装

2016-06-14 11:06 686 查看
memcache和memcached的区别

memcache是php的一个扩展,用于php管理memcached,php-memcache.dll。

如果安装了memcached不安装扩展,那么php无法操控memcached,但是命令行使用起来没有问题 

如果安装了memcache扩展但是没有安装memcached服务,那么这个就无法使用 

只有同时安装了memcached服务和memcache扩展才可以在PHP中使用memcached提高动态网站性能

一、安装memcache的php扩展

1. php_memcache.dll 下载:

下载地址:php_memcache.zip http://www.2cto.com/uploadfile/2012/0713/20120713110240777.zip

2. 把php_memcache.dll放到php的ext目录:

例如:D:\WampServer\bin\php\php5.3.11\ext\php_memcache.dll

3. 打开 php.ini 文件:

我的php.ini的位置:D:\WampServer\bin\php\php5.3.11\php.ini

4. 在 php.ini上增加一行:

extension=php_memcache.dll

5. 重启Wampserver的apache服务

二、安装memcached

1. Memcached-win64 下载:

a. 下载最新版:http://blog.couchbase.com/memcached-windows-64-bit-pre-release-available

b. 直接下载: memcached-win64-1.4.4-14.zip

http://www.2cto.com/uploadfile/2012/0713/20120713110308123.zip

2. 解压放某个盘下面,比如:

D:\WampServer\bin\memcached\memcached.exe

3. 在终端(也即cmd命令界面)下输入以下命令安装windows服务:

D:\WampServer\bin\memcached>memcached.exe -d install

4. 再输入下面命令启动:

D:\WampServer\bin\memcached>memcached.exe -d start

OK~~大功告成

=========== 代码测试 =============

01
$memcache
 
new
 
Memcache;
02
$memcache
->connect(
"localhost"
,11211);
# You might need to set 
"localhost"
 
to 
"127.0.0.1"
03
04
echo
 
"Server's
version: "
 
$memcache
->getVersion()
. 
"\n"
;
05
06
$tmp_object
 
new
 
stdClass;
07
$tmp_object
->str_attr
= 
"test"
;
08
$tmp_object
->int_attr
= 123;
09
10
$memcache
->set(
"key"
,
$tmp_object
,false,10);
11
echo
 
"Store
data in the cache (data will expire in 10 seconds)\n"
;
12
13
echo
 
"Data
from the cache:\n"
;
14
var_dump(
$memcache
->get(
"key"
));
结果:

view
source

print?

01
----------
PhpUnit ----------
02
Server's
version: 1.4.4-14-g9c660c0
03
Store
data 
in
 
the
cache (data will expire 
in
 
10
seconds)
04
Data
from the cache:
05
object(stdClass)
#3
(2) {
06
  
[
"str_attr"
]=>
07
  
string(4) 
"test"
08
  
[
"int_attr"
]=>
09
  
int(123)
10
}
11
12
Output
completed (2 sec consumed) - Normal Termination
来源:http://blog.csdn.net/wusuopubupt/article/details/9128431
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息