I am moving some servers from Ubuntu 16 to Ubuntu 18 and I am having trouble getting php sessions and memcache working.

On the current (Ubuntu 16) setup, there are three servers sharing sessions using memcache (note: not memcached!).

I believe I have replicated the current setup on the new servers, but it doesn't work and I get the following error in the apache error log:

PHP Warning:  session_start(): Failed to read session data: memcache (path: tcp://,tcp://,tcp://

In phpinfo() I see that the session.save_path and session.save_handler are set correctly (as reflected in the log message above).

If I go to any one of the three machines, I can telnet to port 11211 on any of the other servers.

If I look at the logs (set to -vv), I can see stuff happening and quite a few "NOT_FOUND" statements, but I don't really know how to interpret these logs.

In /etc/php/7.2/mods-available/memcache.ini:


On the current (Ubuntu 16) setup, I remember trying both memcached and memcache and figuring out that memcache was the right solution. Trying memcached on the new setup is my last resort, as I feel that memcache should work, and I am just missing something, or something has changed in Ubuntu 18 that I am not aware of.


I had the same issue with PHP 7.1 and memcached, but i think this also will solve your problem.

The issue is with the read function which return false or null if the session doesn't exists. You need to override that function to return an empty string.

How i did it:

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();

i hope this will help

  • Your solution working! – Alex Mar 12 at 9:53

I had the same problem. I have three servers, upgraded one to PHP7.2 and the others running on 7.0 temporarily. I tracked down the issue to a config change between the two for the memcached library. The 7.0 version had memcached.sess_prefix set to memc.sess.key.. The 7.2 has memc.sess.. I fixed it by running this before session_start() on the 7.2 box:

ini_set('memcached.sess_prefix', 'memc.sess.key.');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.