1:下載
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查看狀態
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
<?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();?
瀏覽器開啟testmemcache.php得到
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 1001.2.6Array( [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
4:沒有了