php使用memcache儲存session 伺服器配置方法

來源:互聯網
上載者:User
Memcached-1.4.4-14 For Win32 or Win64


查看 php.ini 可見 session 的預設儲存方式是 files,如下

session.save_handler = files

session 的預設儲存路徑為
對於windows為:C:/Windows/Temp
對於linux為:未知

# windows平台session.save_path = "N:/path"# linux平台session.save_path = "/path"


我們知道是用 files 檔案系統來儲存的話,每次 session 時都會產生一個檔案,效率很低下,如果伺服器上安裝了 memcache ,那麼務必要遷移到 memcache 來儲存 session,做法如下:


方法一(伺服器上修改):php.ini 中全域設定

session.save_handler = memcache  session.save_path = "tcp://127.0.0.1:11211"

方法二(FTP上修改): 在網站跟目錄下的 .htaccess

php_value session.save_handler = memcachephp_value session.save_path = tcp://127.0.0.1:11211

備忘:後面的值加不加英文雙引號都行

方法三(程式上修改): 某一個應用程式中

ini_set("session.save_handler", "memcache");  ini_set("session.save_path", "tcp://127.0.0.1:11211");


使用多個 memcached server 時用英文逗號","隔開,並且和 Memcache::addServer() 文檔中說明的一樣,可以帶額外的參數"persistent"、"weight"、"timeout"、"retry_interval" 等等,類似這樣的:

php_value session.save_path = tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2


以上文檔參考:

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.