1

I was asked to setup a Memcached server on two servers (one on each). For the records, I run PHP 5.6.5. Here is my setup:

memcached.ini:

extension=memcached.so
memcache.allow_failover=1
memcache.session_redundancy=3

php -i | grep memcached

memcached support => enabled
libmemcached version => 1.0.16
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
memcached.sess_binary => 0 => 0
memcached.sess_connect_timeout => 1000 => 1000
memcached.sess_consistent_hash => 0 => 0
memcached.sess_lock_expire => 0 => 0
memcached.sess_lock_max_wait => 0 => 0
memcached.sess_lock_wait => 150000 => 150000
memcached.sess_locking => 1 => 1
memcached.sess_number_of_replicas => 0 => 0
memcached.sess_prefix => memc.sess.key. => memc.sess.key.
memcached.sess_randomize_replica_read => 0 => 0
memcached.sess_remove_failed => 0 => 0
memcached.sess_sasl_password => no value => no value
memcached.sess_sasl_username => no value => no value
memcached.store_retry_count => 2 => 2
memcached.use_sasl => 0 => 0
Registered save handlers => files user memcache memcached
session.save_handler => memcached => memcached

php.ini

session.save_handler = memcached
session.save_path = 'tcp://10.109.6.122:11211,tcp://10.105.164.25:11211'

However, I seem to have a problem with the server redundancy. Just below, I have this grid of test I chose to test. WAS is an Apache server, and MEMCACHE is the Memcached server running along.

+---------+------------+---------+------------+
|  WAS1   | MEMCACHED1 |  WAS2   | MEMCACHED2 |
+---------+------------+---------+------------+
| Started | Started    | Stopped | Stopped    |
| Stopped | Stopped    | Started | Started    |
| Started | Stopped    | Stopped | Started    |
| Stopped | Started    | Started | Stopped    |
+---------+------------+---------+------------+

Down below is the code I use to test. The point is, the $session->id is supposed to increment without trouble.

<?php

require_once "cron_init.php";

$session = new Zend_Session_Namespace('lastCommande');
$session->type = 'test';

if (!isset($session->id)) {
        $session->id = 1;
        echo "Première visite par ici \n" ;
}

else {
        echo "Nombre de visite pour l'instant : " . $session->id . "\n";
        $session->id++;
}

print_r($_COOKIE);

Theorically, everything runs fine. When I "down" one of the servers (both Apache + Memcached from one of the servers), I keep having an incrementing number, but depending on which Memcached server I stop (mainly, Memcached1), the incrementing number I get isn't correct.

For example, if I happen to stop Memcached1, Memcache2 will have its own data. At this moment, $session->id is 18 for Memcached1, and 14 for Memcached2 while they should be both at 14 or 18.

I have tried both memcache.session_redundancy=2 and memcache.session_redundancy=3 because of this reknown PHP bug, but the problem persists in any cases.

What else can I do?

Thank you in advance

Jaeger
  • 125
  • 11
  • You seem to be using `memcached` (not `memcache`) yet you are using `memcache` settings: (`memcache.allow_failover` and `memcache.session_redundancy`). Have you tried looking for the equivalent memcached settings? – Eric Apr 02 '19 at 13:41

1 Answers1

2

As you seem to be using memcached and not memcache, you should use the following settings instead:

memcached.sess_number_of_replicas = 3
memcached.sess_binary_protocol = 1
Eric
  • 213
  • 1
  • 9
  • So replication is actually possible?? I just found it out with your response, and finally found out some information on php.net that I never saw before! Just one question though, how does Memcached handles the redundancy? I can't find anything about that, does it handle it automatically? – Jaeger Apr 03 '19 at 13:29
  • What version of memcached are you using? Some don't seem to support `sess_number_of_replicas`. See https://stackoverflow.com/questions/24953136/php-memcached-sessions-replica-issue – Eric Apr 03 '19 at 14:28
  • I have the 1.4.4 version of Memcached (The latest available version I can get from our "custom" repository). And the 2.2.0 version of the PHP extension. I can't find wether it will work or not anywhere, though.. – Jaeger Apr 03 '19 at 14:44