Marc
Marc

Reputation: 504

Failed to write session data, php and memcached

I have recently tried implementing memcached for session saving in php. I modified the session.save_handler in my php.ini and for the most part it works correctly. Sessions are saved in it. However, once in a while, I get this weird message for certain sessions:

PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (x.x.x.x:11211) in Unknown on line 0.

The session data is the same, way under the 1MB barrier of memcached and I have yet to see a pattern in the occurences of this message... maybe a couple of times every minute. The website is usually under medium load, 150 users concurrently.

Upvotes: 18

Views: 20260

Answers (4)

craig.tadlock
craig.tadlock

Reputation: 1918

If you are using memcache then save_path must have the tcp:// prefix.

If you are using memcached then the save_path should not have the tcp:// prefix.

Upvotes: 17

k0pernikus
k0pernikus

Reputation: 66817

I had a similar issue with symfony2 and memcached on a docker-compose stack.

The error stated:

Warning: Failed to write session data (user). Please verify that the current setting of session.save_path is correct

And the problem was that I had an outdated ./app/config/parameters.yml

Check your memchached setting to fit your needs, e.g.:

parameters:
    session_memcached.host: '%session_memcached_host%'
    session_memcached.port: '%session_memcached_port%'
    session_memcached.prefix: '%session_memcached_prefix%'
    session_memcached.expire: '%session_memcached_expire%'

Upvotes: 0

webmaster
webmaster

Reputation: 2020

The answer is Memcached objects can be maximum of 1MB (default)

if your array or object exceeds this limit, the object will be removed magically :)

All the items in your session will be removed, just saying this because right now at this moment I have experienced it my self

I solved it by starting the Memcached Session server like this

memcached -I 10m

Upvotes: 5

Joe O
Joe O

Reputation: 79

I believe it is something to do with using the memcached extension and it not initializing before the sessions. I switched to using the memcache extension rather than the memcached extension and it works.

session.save_handler = memcache
session.save_path="tcp://192.168.1.103:11211"

Upvotes: 1

Related Questions