windows安裝配置memcache和memcached

1:下載

 php_memcache.dll

memcached.exe


2: 解壓配置

a.memcache 

解壓後得到    php_memcache.dll   和編譯好的    memcached.exe

打開你的php/ext,把    php_memcache.dll    複製進去,比如我的在F:/php/php5/ext 複製進去.

打開php.ini,找到extension,添加

extension=php_memcache.dll

重啓apache.

b.memcached

複製memcached.exe到任意目錄,我放到了 F:/php/mem

CMD進入F:/php/mem 運行 (如果要卸載,把install改成uninstall)

  1. memcached.exe -d install  

開啓服務 命令行輸入

  1. 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

  1. <?php  
  2.     $mem=new Memcache;  
  3.     $mem->connect("localhost",11211);    //pconnect長鏈接  
  4.     //$mem->addServer("www.test.com",11221); //添加多個服務器  
  5.     //$mem->addServer("192.168.1.9",11211);  
  6.   
  7.     $mem->add("mystr","this is a memcache test!",MEMCACHE_COMPRESSED,3600);  
  8.     $str=$mem->get("mystr");  
  9.     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得到

  1. string: this is a memcache test!  
  2. Array ( [0] => aaa [1] => bbb [2] => ccc [3] => ddd )   
  3. object(TestC)[2]  
  4.   public 'name' => string 'Tom' (length=3)  
  5.   public 'age' => int 5  
  6.   public 'money' => int 100  
  7.   
  8. 1.2.6  
  9. 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





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章