1:下载
php_memcache-2.2.6-5.3-vc9-x86.zip
2: 解压配置
a.memcache
解压后得到 php_memcache.dll 和编译好的 memcached.exe
打开你的php/ext,把 php_memcache.dll 复制进去,比如我的在F:/php/php5/ext 复制进去.
打开php.ini,找到extension,添加
extension=php_memcache.dll
保存后复制一份到windows目录下.C:/windows
重启apache.
b.memcached
复制memcached.exe到任意目录,我放到了 F:/php/mem
CMD进入F:/php/mem 运行 (如果要卸载,把install改成uninstall)
memcached.exe -d install
开启服务 命令行输入
net start "memcached Server"
打开任务管理器,可以看见memcached.exe的进程.
启动 命令行输入
F:/php/mem/memcached.exe -d start
上面可以添加参数.,指定内存划分-m 200 ,IP监听 -l 192.168.1.*,端口号-p 11211等.
具体可以参考memcached的php手册.地址在这里.http://php.net/manual/en/book.memcached.php 页面有中文版.
进入telnet localhost 11211
进入. 输入version查看版本,输入stats查看状态
3:浏览器打开phpinfo.php
可以找到memcache.
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 |
新建一个php文件,比如我的testmemcache.php
01.<?php
02. $mem=new Memcache;
03. $mem->connect("localhost",11211); //pconnect长链接
04. //$mem->addServer("www.test.com",11221); //添加多个服务器
05. //$mem->addServer("192.168.1.9",11211);
06.
07. $mem->add("mystr","this is a memcache test!",MEMCACHE_COMPRESSED,3600);
08. $str=$mem->get("mystr");
09. echo "string: ".$str."<br />";
10.
11. $mem->add("myarr",array("aaa","bbb","ccc","ddd"));
12. print_r($mem->get("myarr"));
13.
14. echo '<br />';
15. class TestC
16. {
17. var $name="Tom";
18. var $age=5;
19. var $money=100;
20. }
21. $mem->add("myobj",new TestC);
22.
23. var_dump($mem->get("myobj"));
24. echo '<br />';
25. echo $mem->getVersion()."<br />";
26. echo '<pre>';
27. print_r($mem->getStats());
28. echo '</pre>';
29.
30. $mem->close();
31.?
浏览器打开testmemcache.php得到
01.string: this is a memcache test!
02.Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )
03.object(TestC)[2]
04. public 'name' => string 'Tom' (length=3)
05. public 'age' => int 5
06. public 'money' => int 100
07.
08.1.2.6
09.Array
10.(
11. [pid] => 868
12. [uptime] => 3335
13. [time] => 1316167200
14. [version] => 1.2.6
15. [pointer_size] => 32
16. [curr_items] => 3
17. [total_items] => 6
18. [bytes] => 320
19. [curr_connections] => 3
20. [total_connections] => 15
21. [connection_structures] => 4
22. [cmd_get] => 30
23. [cmd_set] => 27
24. [get_hits] => 29
25. [get_misses] => 1
26. [evictions] => 0
27. [bytes_read] => 2251
28. [bytes_written] => 4515
29. [limit_maxbytes] => 67108864
30. [threads] => 1
31.)
在刚才的telnet界面依次输入get mystr, get myarr, get myobj