php_memcache-2.2.6-5.3-vc9-x86.zip
memcached-1.2.6-win32-bin.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查看状态
可以找到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
<?php $mem=new Memcache; $mem->connect("localhost",11211); //pconnect长链接 //$mem->addServer("www.test.com",11221); //添加多个服务器 //$mem->addServer("192.168.1.9",11211); $mem->add("mystr","this is a memcache test!",MEMCACHE_COMPRESSED,3600); $str=$mem->get("mystr"); echo "string: ".$str."<br />"; $mem->add("myarr",array("aaa","bbb","ccc","ddd")); print_r($mem->get("myarr")); echo '<br />'; class TestC { var $name="Tom"; var $age=5; var $money=100; } $mem->add("myobj",new TestC); var_dump($mem->get("myobj")); echo '<br />'; echo $mem->getVersion()."<br />"; echo '<pre>'; print_r($mem->getStats()); echo '</pre>'; $mem->close(); ?
string: this is a memcache test! Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd ) object(TestC)[2] public 'name' => string 'Tom' (length=3) public 'age' => int 5 public 'money' => int 100 1.2.6 Array ( [pid] => 868 [uptime] => 3335 [time] => 1316167200 [version] => 1.2.6 [pointer_size] => 32 [curr_items] => 3 [total_items] => 6 [bytes] => 320 [curr_connections] => 3 [total_connections] => 15 [connection_structures] => 4 [cmd_get] => 30 [cmd_set] => 27 [get_hits] => 29 [get_misses] => 1 [evictions] => 0 [bytes_read] => 2251 [bytes_written] => 4515 [limit_maxbytes] => 67108864 [threads] => 1 )
在刚才的telnet界面依次输入get mystr, get myarr, get myobj