This article mainly introduces how PHP saves sessions to the memcache server. it involves PHP session operations and memcache related skills, for more information about how to save a session to the memcache server, see the example in this article. We will share this with you for your reference. The details are as follows:
The traditional session is written to the server file. you can see in php. ini that the list is as follows:
Session. save_handler = filessession. save_path = "sess save path"
However, if there are many website users, session access will inevitably affect the website speed. Because the file reading speed is very low.
As we all know, memcache, as a memory cache server, uses a hash algorithm to read data in the form of key-> value, which is much faster than reading files.
The configuration for saving 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 = memcachesession. save_path = "tcp: // Mem server 1: port number, tcp: // Mem Server 2: port number ..."
Method 2:
Use the ini_set function in the php file for configuration. this method solves the php configuration problem of the shared server.
<? Php .... ini_set ("session. save_handler "," memcache "); ini_set (" session. save_path "," tcp: // Mem server 1: port number, tcp: // Mem Server 2: port number... ");...?>
Restart the Web server!
In this case, the session will not be saved as a file, but will be saved to the Memcache server. the key to be saved is session_id.
Telnet to the memcache server for get View
Telnet memcache server port number