2014年8月19日 星期二

在 windows 上安裝 PHP memcached

安裝 PHP 的 memcache extension
  1. 下載 php_memcache.dll
    依自己的PHP版本到 http://windows.php.net/downloads/pecl/releases/memcache/ 下載相對應的版本,
    例如我是 PHP5.4 nts 版本,所以下載
    http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/php_memcache-3.0.8-5.4-nts-vc9-x86.zip
  2. 解壓縮 php_memcache-3.0.8-5.4-nts-vc9-x86.zip,將裡面的 php_memcache.dll 放到 PHP 的 ext 資料夾內。
  3. 修改 php.ini,增加一行
    extension=php_memcache.dll
  4. 重新啟動 Apache,安裝成功的話,phpinfo() 可看到 memcache 的相關資訊。

到此步驟,PHP 已經可以去連接其他 memcached Server 了。
若要繼續裝 memcached Server,繼續往下。

安裝 memcached Server
  1. 下載 windows 版 memcached
    http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip
  2. 將 memcached-1.2.6-win32-bin.zip 解壓縮,我解壓縮到 D:\memcached
  3. 將 memcached 安裝為 windows service
    用系統管理員身分,開啟 cmd 命令提示字元,再執行以下指令
    D:\memcached>memcached -d install
  4. 啟動 memcached
    D:\memcached>memcached -d start
  5. 其他可以用的參數,可以用 memcached -help 查看
    D:\memcached>memcached -help
    memcached 1.2.6
    -p <num>      TCP port number to listen on (default: 11211)
    -U <num>      UDP port number to listen on (default: 0, off)
    -s <file>     unix socket path to listen on (disables network support)
    -a <mask>     access mask for unix socket, in octal (default 0700)
    -l <ip_addr>  interface to listen on, default is INDRR_ANY
    -d start          tell memcached to start
    -d restart        tell running memcached to do a graceful restart
    -d stop|shutdown  tell running memcached to shutdown
    -d install        install memcached service
    -d uninstall      uninstall memcached service
    -r            maximize core file limit
    -u <username> assume identity of <username> (only when run as root)
    -m <num>      max memory to use for items in megabytes, default is 64 MB
    -M            return error on memory exhausted (rather than removing items)
    -c <num>      max simultaneous connections, default is 1024
    -k            lock down all paged memory.  Note that there is a
                  limit on how much memory you may lock.  Trying to
                  allocate more than that would fail, so be sure you
                  set the limit correctly for the user you started
                  the daemon with (not for -u <username> user;
                  under sh this is done with 'ulimit -S -l NUM_KB').
    -v            verbose (print errors/warnings while in event loop)
    -vv           very verbose (also print client commands/reponses)
    -h            print this help and exit
    -i            print memcached and libevent license
    -b            run a managed instanced (mnemonic: buckets)
    -P <file>     save PID in <file>, only used with -d option
    -f <factor>   chunk size growth factor, default 1.25
    -n <bytes>    minimum space allocated for key+value+flags, default 48

參考:
http://stackoverflow.com/questions/14777857/how-to-install-and-use-memcached-in-windows-for-php/23320151#23320151
http://shiki.me/blog/installing-memcached-for-php-5-3-on-windows-7/

沒有留言:

張貼留言