在为php安装了memcache模块后查看该模块的说明文件,发现他还可以直接作为php的session handler使用,而无需做做额外的编码处理。
设置方法很简单,只要修改php.ini中的以下键的值:
session.save_handler = memcache
session.save_path = 'tcp://192.168.0.1:11211'
#有多个时直接用","分隔即可
要测试一下是否真的用上了memcache,可以先获取使用的PHPSESSID,然后将其作为KEY用memcach去读一下,就知道了。
使用memcache做php的session handler好处
使用内存存放session信息,不经过磁盘,数据库等,速度快
可以多台机器共用一个/组memcached服务器,达到多台机器共享session信息,方便多机集群的session问题处理。
…
使用memcache做为php的session handler坏处
首先memcached的服务必须正常工作,否则php的session相关功能将不起作用,这样php的处理就多了一层外面的依赖。
由于memcached是使用内存的,这样当用户量比较大时,就可能由于内存方面原因导致session时长上的问题,session的实际失效时长达不到设定的失效时长(由于memcached在内存不够下的处理机制决定)
由于memcached的内存管理机制,当session存储的数据超过1MB的时候有数据丢失问题(不过一般不会有人在session中存放这么多的信息吧)。
…
根据以上的一些情况决定自己在实际环境中是否使用memcache做为php的session handler

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools