memcached - PHP implements memcache to store session issues

WBOY
Release: 2016-08-04 09:20:44
Original
874 people have browsed it

First set session.save_handler = user, note not memcache.

Then the custom class Session implements the SessionHandlerInterface interface, creates the object, and registers session_set_save_handler, so that every time, for example:

$_SESSION['aaa'] = '123';

When

, PHP will call Session->write(). In the function, I manually insert records with sess- as the prefix and session_id() as the suffix into memcache, for example: key = sess-4fqrbhed9f3grq4p4ssbljg867.

There is a very strange problem at this time. Every time I follow $_SESSION['aaa'] = '123';, I can get the data corresponding to this session_id() from memcache, but delete $_SESSION. ['aaa'] = '123'; After that, the data in memcache will be automatically deleted.

Reply content:

First set session.save_handler = user, note not memcache.

Then the custom class Session implements the SessionHandlerInterface interface, creates the object, and registers session_set_save_handler, so that every time, for example:

$_SESSION['aaa'] = '123';

When

, PHP will call Session->write(). In the function, I manually insert records with sess- as the prefix and session_id() as the suffix into memcache, for example: key = sess-4fqrbhed9f3grq4p4ssbljg867.

There is a very strange problem at this time. Every time I follow $_SESSION['aaa'] = '123';, I can get the data corresponding to this session_id() from memcache, but delete $_SESSION. ['aaa'] = '123'; After that, the data in memcache will be automatically deleted.

Modify php.ini
session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211;tcp://127.0.0.1:11212;tcp://127.0.0.1:11213

Solved, the reason is that SessionHandlerInterface::read() is not implemented, causing $_SESSION to be set to a null value after refreshing, which then causes this null value to be written after calling write.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template