<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Memcached版本:Memcached Win32 1.2.6,
下载地址:
http://code.jellycan.com/memcached/
。
以管理员身份进入命令行,运行安装命令:
以管理员身份进入命令行,运行安装命令:
memcached -d install -l 127.0.0.1 -m 1024 -c 2048
参数说明:
-d install 安装为Windows服务
-l 绑定的IP
-m 使用的最大内存(MB),默认64M
-c 最大并发连接数,默认1024
参数说明:
-d install 安装为Windows服务
-l 绑定的IP
-m 使用的最大内存(MB),默认64M
-c 最大并发连接数,默认1024
再输入: c:\memcached\memcached.exe -d start启动。(需要注意的: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了)。
下载php_memcache.dll 文件,把它放入php文件夹的ext目录中。
在php.ini加入一行引用扩展,代码如下:
extension=php_memcache.dll
接着在 php.ini 文件里加上:
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211
最好就放在刚才写 "extension=php_memcache.dll" 的下面。(这是默认的一些配置)
重新启动Apache,然后查看一下phpinfo,如果有 memcache 的说明,那么就说明安装成功啦!
进入
telnet localhost 11211
浏览器打开phpinfo.php
可以找到memcache.
memcache support
|
enabled
|
Active persistent connections
|
0
|
Version
|
2.2.6
|
Revision
|
$Revision: 296899 $
|
Directive
|
Local Value
|
Master Value
|
memcache.allow_failover
|
1
|
1
|
memcache.chunk_size
|
8192
|
8192
|
memcache.default_port
|
11211
|
11211
|
memcache.default_timeout_ms
|
1000
|
1000
|
memcache.hash_function
|
crc32
|
crc32
|
memcache.hash_strategy
|
standard
|
standard
|
memcache.max_failover_attempts
|
20
|
20
|
写一个 example.php 文件(更多使用方法可以参看 PHP 手册里的 Memcache Functions 使用说明),测试代码如下:
<?php
$memcache
=
new
Memcache;
$memcache
->
connect
(
'localhost'
,
11211
)
or
die
(
"Could not connect"
);
$version
=
$memcache
->
getVersion
();
echo
"Server's version: "
.
$version
.
"<br/>\n"
;
$tmp_object
=
new
stdClass;
$tmp_object
->str_attr =
'test'
;
$tmp_object
->int_attr =
123
;
$memcache
->
set
(
'key'
,
$tmp_object
, false,
10
)
or
die
(
"Failed to save data at the server"
);
echo
"Store data in the cache (data will expire in 10 seconds)<br/>\n"
;
$get_result
=
$memcache
->
get
(
'key'
);
echo
"Data from the cache:<br/>\n"
;
var_dump
(
$get_result
);
?>
如果输出如下,则测试成功:
Server's version: 1.4.5
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }
知识点:
Memcached的基本参数设置:
·
-p 监听的端口
·
-l 连接的IP地址, 默认是本机
·
-d start 启动memcached服务
·
-d restart 重起memcached服务
·
-d stop|shutdown 关闭正在运行的memcached服务
·
-d install 安装memcached服务
·
-d uninstall 卸载memcached服务
·
-u 以的身份运行 (仅在以root运行的时候有效)
·
-m 最大内存使用,单位MB。默认64MB
·
-M 内存耗尽时返回错误,而不是删除项
·
-c 最大同时连接数,默认是1024
·
-f 块大小增长因子,默认是1.25
·
-n 最小分配空间,key+value+flags默认是48
·
-h 显示帮助<-->
转载于:https://blog.51cto.com/mycnarms/782507