Home  >  Article  >  Backend Development  >  How to save session to memcache server in PHP, sessionmemcache_PHP tutorial

How to save session to memcache server in PHP, sessionmemcache_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:00:26725browse

How to save session to memcache server in PHP, sessionmemcache

This article describes the method of saving session to memcache server in PHP. Share it with everyone for your reference, the details are as follows:

The traditional session is written to the server file, which can be seen in php.ini. The list is as follows

session.save_handler = files
session.save_path = "sess保存路径"

However, if the website has many users, session access will inevitably affect the speed of the website. Because the file reading speed is very low.

As we all know, memcache, as a memory cache server, reads data in the form of key->value through a hash algorithm, and its speed is much higher than reading files.

The configuration to save the session to the memcache server is as follows:

Method 1:

Open the php.ini file and modify the following two parameters:

session.save_handler = memcache
session.save_path = "tcp://Mem服务器1:端口号,tcp://Mem服务器2:端口号..."

Method 2:

Use the ini_set function in the php file to configure. This method will solve the php configuration problem of the shared server

<&#63;php
....
ini_set("session.save_handler", "memcache");
ini_set("session.save_path", "tcp://Mem服务器1:端口号,tcp://Mem服务器2:端口号...");
....
&#63;>

Restart the web server!

At this time, the session will not be saved in the form of a file, but will be saved to the Memcache server. The saved key is session_id

Telnet to the memcache server and get the view

telnet memcache server port number

Readers who are interested in more content related to PHP caching can check out the special topic of this site: "Summary of PHP Caching Technology"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • A summary of the methods of setting up sessions in PHP and using memcache to store them
  • Three configuration methods for using memcache to store sessions in PHP
  • How to set up session in PHP into memcached
  • Detailed explanation of using memcache to store session based on PHP
  • Use Memcached to implement session mechanism under PHP to replace PHP’s native session support

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1093708.htmlTechArticleHow to save session to memcache server in PHP, sessionmemcache This article describes the method of saving session to memcache server in PHP. Share it with everyone for your reference, the details are as follows:...
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