Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> Web 伺服器

Windows IIS 環境安裝 Memcached 完整步驟:服務部署、PHP 擴充啟用與驗證

編輯:Web 伺服器

一、安裝 Memcached 服務

  1. 下載 memcached-1.2.1-win32.zip(或較新版),解壓至 C:\memcached。
  2. 以管理員身分開啟 CMD,切換至解壓目錄:
    cd C:\memcached
  3. 安裝為 Windows 服務並啟動:
    memcached.exe -d install
    memcached.exe -d start
  4. 驗證:工作管理員 → 服務 → memcached 狀態為「正在執行」;或 tasklist | findstr memcached。

二、安裝 PHP Memcache 擴充

  1. 確認 PHP 版本(如 5.2.9),下載對應 pecl-5.2.6-Win32.zip(含 php_memcache.dll)。
  2. 解壓,將 php_memcache.dll 複製至 PHP ext 目錄(如 D:\php5\ext)。

三、配置 php.ini 啟用擴充

; 在 extension 區塊下新增
extension=php_memcache.dll

儲存後重啟 IIS(iisreset)。

四、驗證安裝成功

  1. 瀏覽 phpinfo() 頁面,搜尋 memcache 區塊出現即成功。
  2. 執行測試腳本:
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;  // 輸出 "This is a test!" 表示環境正常
?>

五、Memcached 常用啟動參數

參數說明
-p監聽埠(預設 11211)
-l綁定 IP(預設 127.0.0.1)
-m最大記憶體 MB(預設 64)
-c最大同時連線(預設 1024)
-d start|restart|stop|install|uninstall服務控制
-u執行身分(僅 root 有效)
-f區塊增長因子(預設 1.25)
-n最小分配空間 bytes(預設 48)

六、生產環境建議

  • 記憶體設定為實體記憶體 50-70%(-m 1024 等)。
  • 防火牆僅開放內網應用伺服器 IP 存取 11211 埠,嚴禁公網直連。
  • 啟用 SASL 認證或 VPN 隔離,防止未授權存取。
  • 監控 stats 指標(hit rate、evictions、memory usage),適時擴容或調整 -f、-n。
Copyright © Windows教程網 All Rights Reserved