Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.6 Sessions + Memcache(d)

I am having a strange problem, since i have upgraded PHP from 5.4 to 5.6. I have never seen the error myself, but the logs a full every day with this message:

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

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

Everything was working perfect for a very long time, and I started having this problem right after PHP upgrade, so it's not related with memcached config, or something like this. Maybe I am missing something? Maybe 5.6 requires some additional configs in its ini file? I just cant figure it out.

At the moment I am kind of stuck, and I hope anyone can help me with advice. I can try switching back to 5.4, or to 5.5, but that's not really an option, I would really like to stick to 5.6.

like image 958
Andrei Carpov Avatar asked Jan 02 '15 13:01

Andrei Carpov


1 Answers

There are 2 Extension for php, memcache and memcached.

memcached extension is based on libmemcache, and you should prefer that one anyway.

In my experience current versions of the memcache daemon did not play nice with the memcache extension. Storing data worked, but I've experienced substantial performance issues for writing data into the session after the first request (first request for completely new session was fine and fast, every following request took up to 10 seconds !). Replacing memcache with memcached fixed this particular problem.

Warning: The syntax for session.save_path for memcached was slightly different. I had to ommit the tcp:// or it would 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"
like image 168
Ingo Avatar answered Nov 11 '22 12:11

Ingo