Home  >  Article  >  Backend Development  >  MEMCACHE as PHP SESSION HANDLER_PHP Tutorial

MEMCACHE as PHP SESSION HANDLER_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:16:19793browse

After installing the memcache module for PHP, I checked the module’s description file and found that it can also be used directly as PHP’s session handler without additional coding.

The setting method is very simple, just modify the values ​​of the following keys in php.ini:

session.save_handler = memcache
session.save_path = 'tcp://192.168.0.1:11211'

#If there are multiple, just use "," to separate them
To test whether memcache is really used, you can first obtain the PHPSESSID used, and then use memcach to read it as the KEY, and you will know.
Benefits of using memcache as PHP session handler


Use memory to store session information without going through disks, databases, etc., fast
Multiple machines can share one/group memcached server, so that multiple machines can share session information, which facilitates the processing of session issues in multi-machine clusters.

Disadvantages of using memcache as PHP session handler

First of all, the memcached service must work normally, otherwise the session-related functions of PHP will not work, so PHP processing will have an extra layer of external dependencies.
Since memcached uses memory, when the number of users is relatively large, there may be problems with session length due to memory reasons. The actual failure time of the session will not reach the set failure time (due to memcached's processing under insufficient memory). Determined by mechanism)
Due to the memory management mechanism of memcached, there is a data loss problem when the data stored in the session exceeds 1MB (but generally no one stores so much information in the session).

Based on the above situations, decide whether to use memcache as PHP's session handler in the actual environment

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628703.htmlTechArticleAfter installing the memcache module for php, I checked the module's description file and found that it can also be used directly as a php session. handler without doing additional coding. The setting method is very...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn