Home > Article > Backend Development > memcached - PHP implements memcache to store session issues
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.
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.