Can't seem to get sessions saved in memcached

Can't seem to get sessions saved in memcached

Matej Zerovnik -
回帖数:12
Hello!

I'm having troubles saving sessions in memcached...

I'm running 2 memcached servers:
17878 ?        Ssl    0:09 /usr/bin/memcached -u memcached -p 11212 -m 1024 -c 1024 -d
17886 ?        Ssl    0:00 /usr/bin/memcached -u memcached -p 11211 -m 1024 -c 1024 -d

Inside MUC, I add a new memcached store and select it as app cache. For this I select the one on 11212 port.

In config.php I add the following, which should enable sessions saving in memcached:
$CFG->session_handler_class = '\core\session\memcached';
$CFG->session_memcached_save_path = '127.0.0.1:11211';
$CFG->session_memcached_prefix = 'memc.sess.key.';
$CFG->session_memcached_acquire_lock_timeout = 120;
$CFG->session_memcached_lock_expire = 7200;       // Ignored if memcached extension <= 2.1.0

If I then run my benchmark and check phpmemcached, I can see app cache being populated, but session cache is not. What did I do wrong?
Where can I check why it's not being used?

Matej


回复Matej Zerovnik

Re: Can't seem to get sessions saved in memcached

Jeff White -
Do you see memcached in your php info? Do you see memcached.ini listed in php.d? 
回复Jeff White

Re: Can't seem to get sessions saved in memcached

Matej Zerovnik -

Hello!

I took a good look at phpinfo again and notices defualt session handler wasnt set to memcached, although it was set in php.ini.

As far as I remember, I had to uncomment 'session.save_handler=memcached' in z-memcached.ini file in php.d folder. I think that forced it to work.


Matej

回复Matej Zerovnik

Re: Can't seem to get sessions saved in memcached

Daniel Nelson -

Moodle 2.8.6

RHEL 7

PHP 5.4.16

I'm having a similar problem.

$CFG->session_handler_class = '\core\session\memcached';
$CFG->session_memcached_save_path = '128.119.105.102:11212,128.119.105.103:11212';
$CFG->session_memcached_prefix = 'memc.sess.key.';
$CFG->session_memcached_acquire_lock_timeout = 120;
$CFG->session_memcached_lock_expire = 7200;

nobody   23044     1  0 11:00 ?        00:00:02 /bin/memcached -d -m 128 -p 11211 -c 2048 -t 4 -u nobody
nobody   23051     1  0 11:00 ?        00:00:00 /bin/memcached -d -m 1024 -p 11212 -c 2048 -t 4 -u nobody

I tried the solution I found in following comments of uncommenting session.save_handler=memcached in /php.d/z-memcached but that doesn't seem to have done anything. 

I still get nothing when I dump the memcached memory for the session cache (11212 in my case) on either node. 

PHPINFO (Sessions)

session

Session Support enabled
Registered save handlers files user memcache memcached
Registered serializer handlers php php_binary igbinary msgpack wddx

DirectiveLocal ValueMaster Value
session.auto_startOffOff
session.cache_expire180180
session.cache_limiternocachenocache
session.cookie_domainno valueno value
session.cookie_httponlyOffOff
session.cookie_lifetime00
session.cookie_path//
session.cookie_secureOnOff
session.entropy_file/dev/urandom/dev/urandom
session.entropy_length3232
session.gc_divisor10001000
session.gc_maxlifetime3456001440
session.gc_probability11
session.hash_bits_per_character55
session.hash_function00
session.nameMoodleSessionPHPSESSID
session.referer_checkno valueno value
session.save_handlerusermemcached
session.save_path/var/lib/php/sessionno value
session.serialize_handlerphpphp
session.upload_progress.cleanupOnOn
session.upload_progress.enabledOnOn
session.upload_progress.freq1%1%
session.upload_progress.min_freq11
session.upload_progress.namePHP_SESSION_UPLOAD_PROGRESSPHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefixupload_progress_upload_progress_
session.use_cookiesOnOn
session.use_only_cookiesOnOn
session.use_trans_sid00

--

Daniel




回复Daniel Nelson

Re: Can't seem to get sessions saved in memcached

Daniel Nelson -

I've also tried this same setup with save path set to a single instance $CFG->session_memcached_save_path = '128.119.105.102:11212' and it made no difference.

--

Daniel


回复Daniel Nelson

Re: Can't seem to get sessions saved in memcached

Jeff White -

how is the memcached.ini set up? Were you attempting to have session failover by listing the two memcached instances in config.php?

You may have made the same mistake I made a while back. I put the memcache settings AFTER this line in config.php:

require_once(dirname(__FILE__) . '/lib/setup.php'); // Do not edit

If you put anything after that line moodle will not read it. It was easy to do if you had moodle make the config.php during the install instead of building off of config-dist.php. 

回复Daniel Nelson

Re: Can't seem to get sessions saved in memcached

Paul Verrall -

If you are using RHEL 7 with the default SELinux configuration you will not be able to use memcached on a non standard port, i.e. 11212

You can either disable SELinux (not recommended) or you can enable memcached to use the extra port like so,

semanage port -a -t memcache_port_t -p tcp 11212

It also looks like you are allocating a whole gig of RAM to memcached sessions which in my experience is WAY more than you'll ever need, start small, monitor and increase if you need to, I'd be surprised if you needed more than the default 64 meg.

回复Daniel Nelson

Re: Can't seem to get sessions saved in memcached

Mehmet Sen -

I had the same problem, restart also the php-fpm if you using it


$ sudo systemctl restart nginx

$ sudo systemctl restart php-fpm


回复Matej Zerovnik

Re: Can't seem to get sessions saved in memcached

Tony Box -

Also having a similar issue, except that mine does not allow me to associate session caches with memcached.

On the Caching config page in moodle, I see the following:


Notice how the Memcached option only allows the "Application" mode! Aren't you supposed to be able to configure sessions to work with memcached?

If I try to edit the mappings of a specific "Known cache definition" which is a "Session" cache, it won't let me choose my memcached instance to use. How are you supposed to get sessions stored in memcached?

回复Tony Box

Re: Can't seem to get sessions saved in memcached

James McLean -
Configuration for sessions to use Memcache is done via config.php: https://docs.moodle.org/28/en/Session_handling#Memcached


Make sure you're using a different Memcache instance than any MUC instances if you're using those, or sessions will be cleared every time the cache is cleared (more often than you think, and usually not when you request it!)