Failed to write session data, php and memcached

Asked
Active3 hr before
Viewed126 times

8 Answers

sessionwritefailed
90%

If a PHP session exceeds the maximum Memcached key/slab size, it will throw a fatal PHP error that it failed to write the session data.,Now to fix it, you can modify your Memcached configuration and add an option to increase the maximum key/slab size in Memcached.,If you restart Memcached, you’ll get a friendly heads-up that increasing the key/slab size also increases the minimum memory requirements:,In particular, we’ve modified the OPTIONS= block and added the -l (lower case L) and -I (upper case i) to that list. The -I increases the maximum key/slab size in Memcached, as explained by the manual.

The problem manifested itself with working PHP sessions for the “frontend”, the normal users that log in and do some shopping. However, for all backend admins, when they wanted to log in they got a PHP error message:

Warning: Unknown: Failed to write session data(memcached).Please verify that the current setting of session.save_path is correct(127.0 .0 .1: 11211) in Unknown on line 0
load more v
88%

Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct., Stack Overflow Public questions & answers , Meta Stack Overflow , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

My php.ini settings:

session.save_handler = memcache
session.save_path = "tcp://64.233.191.255:11211"
load more v
72%

I'm noticing an intermittent issue with our Memcached session handler. The error that occurs is:,Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct.,It seems to be an intermittent issue that occurs 5 or 6 times a day to various users.,Failed to write, and not due to blocking: Connection reset by peer.

My php.ini settings:

session.save_handler = memcache
session.save_path = "tcp://64.233.191.255:11211"

Note that I've also used:

session.save_path = "tcp://64.233.191.255:11211?persistent=1&weight=1&timeout=1&retry_interval=15"
load more v
65%

I'm noticing an intermittent issue with our Memcached session handler. The error that occurs is:,Unknown: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct.,It seems to be an intermittent issue that occurs 5 or 6 times a day to various users.,Get answers to millions of questions and give back by sharing your knowledge with others.

My php.ini settings:

session.save_handler = memcache
session.save_path = "tcp://64.233.191.255:11211"
load more v
75%

Using php-memcached occasionally ended up with "Failed to write session data" (below). But changing it to php-memcache do not show any error. (or error not available?) Would like to make php-memcached works. Thanks in advanced.,Hi, am having strange experience with php-memcached after upgraded from php-memcache serving php sessions.,By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.,PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (10.2.2.1:11211,10.2.2.2:11211) in Unknown on line 0

Please try to define connection proto:
php_admin_value[session.save_path] = 'tcp://10.2.2.1:11211,tcp://10.2.2.2:11211'

php_admin_value[session.save_path] = 'tcp://10.2.2.1:11211,tcp://10.2.2.2:11211'
40%

On the current (Ubuntu 16) setup, there are three servers sharing sessions using memcache (note: not memcached!).,I am moving some servers from Ubuntu 16 to Ubuntu 18 and I am having trouble getting php sessions and memcache working.,created a class which extended SessionHandler,Please be sure to answer the question. Provide details and share your research!

created a class which extended SessionHandler

class MyMemcachedSessionHandler extends SessionHandler {
   public
   function read($id) {
      $data = parent::read($id);
      if (empty($data)) {
         return '';
      } else {
         return $data;
      }
   }
}

and before session_start() i registered it

$myMemcachedSessionHandler = new MyMemcachedSessionHandler();
session_set_save_handler($myMemcachedSessionHandler);
load more v
22%

Several web servers servers (using php-fpm – fastcgi) connect to a single memcached server to share sessions.,The PHP configuration (php.ini) is as simple as that:,This is how you can enable PHP sessions to be stored in the memcached server with IP 10.10.10.10 and tell the driver to use persistent connections. Note we use the binary PHP module memcached, not memcache, which is the old driver.,The persistence is handled by the PHP module, not the library, which it wraps and it is per process not per all PHP fpm (fastcgi) processes. Apparently, sometimes this functionality just get corrupted and many of those errors begin to appear in the logs – most of the time a reload of the php-fpm after a long period of time. Even a restart did not help, so the real solution, which always works for us is

Several reports in the Internet with such error:

[22 - Mar - 2019 21: 35: 20 Africa / Tunis] PHP Warning: Unknown: Failed to write session data(memcached).Please verify that the current setting of session.save_path is correct(PERSISTENT = 2 10.10 .10 .10: 11211) in Unknown on line 0[22 - Mar - 2019 21: 35: 21 Africa / Lagos] PHP Warning: Unknown: Failed to write session data(memcached).Please verify that the current setting of session.save_path is correct(PERSISTENT = 2 10.10 .10 .10: 11211) in Unknown on line 0[22 - Mar - 2019 13: 35: 21 America / Los_Angeles] PHP Warning: Unknown: Failed to write session data(memcached).Please verify that the current setting of session.save_path is correct(PERSISTENT = 2 10.10 .10 .10: 11211) in Unknown on line 0
load more v
60%

If you are using memcache then save_path must have the tcp:// prefix.,If you are using memcached then the save_path should not have the tcp:// prefix.,I solved it by starting the Memcached Session server like this ,All the items in your session will be removed, just saying this because right now at this moment I have experienced it my self

I solved it by starting the Memcached Session server like this

memcached - I 10 m

Other "session-write" queries related to "Failed to write session data, php and memcached"