PHP 5.6 Sessions + Memcache (d)

I had a strange problem since I updated PHP from 5.4 to 5.6. I have never seen an error on my own, but the logs are filled every day with this message:

session_write_close (): Failed to write session data (memcached). Verify that the current session.save_path setting is correct (127.0.0.1:11211)

This does not always happen, but only for certain users. And this happens on three different servers with PHP ~ 5.6 and Memcached on the latest Debian. I tried switching the Memcached extension to Memcache (of course with changing save_handler in php.ini) and the problem still persists. I also tried disabling session lock in php.ini. The problem is certainly related to PHP because I tested the Memcached daemon itself with a Perl script, and there was not a single connection error.

Everything worked perfectly for a very long time, and I started this problem right after updating PHP, so it is not related to memcached configuration or something like that. Maybe I missed something? Maybe 5.6 requires some additional configs in its ini file? I just can't figure it out.

At the moment, I'm kind of stuck, and I hope someone can help me. I can try to return to 5.4 or 5.5, but this is not quite an option, I would really like to stick to 5.6.

+6
source share
2 answers

There are 2 extensions for php, memcache and memcached .

Expansion

memcached is based on libmemcache, and you should use it anyway.

In my experience, current versions of the memcache daemon did not play well with the memcache extension. The data storage worked, but I had significant performance problems for writing data to the session after the first request (the first request for a completely new session was beautiful and fast, each subsequent request took up to 10 seconds!). Replacing memcache with memcached fixes this particular problem.

Warning The syntax for session.save_path for memcached was slightly different. I had to omit tcp:// , otherwise it will not work

So for memcached use:

 session.save_path = "127.0.0.1:11211" 

And for memcache use:

 session.save_path = "tcp://127.0.0.1:11211" 
+1
source

Please make sure the session in your php.ini is as follows.

 session.save_path = "tcp://127.0.0.1:11211" 

or for UNIX sockets

 session.save_path = "unix:///var/run/memcached.sock" 
0
source

Source: https://habr.com/ru/post/980430/


All Articles