PHP memcached session redundancy

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
alexus's picture

I'm trying to use Memcache API and Integration | Drupal.org along with How To Share PHP Sessions on Multiple Memcached Servers on Ubuntu 14.04.

OS & Packages:

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.6 (Santiago)
# rpm -q httpd php php-pecl-memcache
httpd-2.2.15-39.el6.x86_64
php-5.3.3-40.el6_6.x86_64
php-pecl-memcache-3.0.5-4.el6.x86_64
#

/etc/php.d/memcache.ini

# grep -v ^\; /etc/php.d/memcache.ini
extension=memcache.so
memcache.allow_failover=1
memcache.session_redundancy=2
session.save_handler=memcache
session.save_path='tcp://192.168.52.142:11211, tcp://192.168.52.143:11211'
#

PHP information:

# php -i | grep -E 'memcache.allow_failover|memcache.session_redundancy|session.save_handler|session.save_path'
memcache.allow_failover => 1 => 1
memcache.session_redundancy => 2 => 2
session.save_handler => memcache => memcache
session.save_path => tcp://192.168.52.142:11211, tcp://192.168.52.143:11211 => tcp://192.168.52.142:11211, tcp://192.168.52.143:11211
#

TCP wise: .142 is able to get to .143:11211, and .143 is able to get to .142:11211, SELinux is in Permissive mode.

I am able to see some chunks stored in one memcached server, but not in another.

Please advise.

Comments

I posted same question to

You could try to use Memcache

Spleshka's picture

You could try to use Memcache Storage module for your case. It provides out-of-the-box solution for storing sessions in memcached (no needs to configure php.ini). And you can configure to store sessions in memcached across multiple servers right in settings.php. Here is the example:

<?php
$conf
['memcache_servers'] = array(
 
'127.0.0.1:11211' => 'default', // Server 1
 
'127.0.0.1:11211' => 'sessions_instance', // Server 1
 
'127.0.0.2:11212' => 'sessions_instance', // Server 2
);

# Note that you need to set up this for 'sessions' AND for 'users' bins.
$conf['memcache_bins'] = array(
 
'sessions'  => 'sessions_instance',
 
'users'     => 'sessions_instance',
);
?>

See README.txt if you need more info.

Would this be the session

adammalone's picture

Would this be the session storage that's in the unstable directory in the Drupal 7 module with the note in the README to the effect that is not recommended for use in production?

http://cgit.drupalcode.org/memcache/tree/unstable/memcache-session.inc
http://cgit.drupalcode.org/memcache/tree/README.txt#n355

Please pay your attention at

Spleshka's picture

Please pay your attention at the module name. I wrote about Memcache Storage, not about Memcache.

unfortunately this won't work

alexus's picture

unfortunately this won't work for me as I'm using pressflow-6, this module supports drupal-7+.

while it's in plans to upgrade, I'd still prefer to do it on non-application level, although I'm sure there are some benefits in going that route as well..

I want to remind you that

Spleshka's picture

I want to remind you that Drupal overrides default session handlers. I don't think that change of session storage to memcached on non-application level will have any effect. See drupal_session_initialize():

<?php
  session_set_save_handler
('_drupal_session_open', '_drupal_session_close', '_drupal_session_read', '_drupal_session_write', '_drupal_session_destroy', '_drupal_session_garbage_collection');
?>

I want to remind you that

Spleshka's picture

-- UFO and double-submit placed this comment here --