简体   繁体   中英

PHP Memcache failed to write session data

I have two servers that I'm installing PHP Memcache for sessions on. One worked without an issue, the other I've been struggling with. The servers have the same php and libs version, same OS ( RHEL 6.7 ), different memory size, different disk space, but I can't narrow down the issue.

I've written a small php file to create a session and attempt session_write_close(). For one system I get no error and sessions are persisting with memcache, for the other, I get this:

Warning: session_write_close(): Failed to write session data (memcache). 
Please verify that the current setting of session.save_path is correct (tcp://localhost:11211?persistent=1&weight=1&timeout=1&retry_interval=15)

This is my /etc/php.d/memcache.ini

; ----- Enable memcache extension module 
extension=memcache.so

; ----- Options for the memcache module

;  Whether to transparently failover to other servers on errors
;memcache.allow_failover=1
;  Data will be transferred in chunks of this size
;memcache.chunk_size=32768
;  Autocompress large data
;memcache.compress_threshold=20000
;  The default TCP port number to use when connecting to the memcached server
;memcache.default_port=11211
;  Hash function {crc32, fnv}
;memcache.hash_function=crc32
;  Hash strategy {standard, consistent}
;memcache.hash_strategy=consistent
;  Defines how many servers to try when setting and getting data.
;memcache.max_failover_attempts=20
;  The protocol {ascii, binary} : You need a memcached >= 1.3.0 to use the binary protocol
;  The binary protocol results in less traffic and is more efficient
;memcache.protocol=ascii
;  Redundancy : When enabled the client sends requests to N servers in parallel
;memcache.redundancy=1
;memcache.session_redundancy=2
;  Lock Timeout
;memcache.lock_timeout = 15

; ----- Options to use the memcache session handler

;  Use memcache as a session handler
session.save_handler=memcache
;  Defines a comma separated of server urls to use for session storage
session.save_path="tcp://localhost:11211?persistent=1&weight=1&timeout=1&retry_interval=15"

And this is my /etc/sysconfig/memcached

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

Again, these files are identical between my two servers, one works and one doesn't. I'm not sure how to even go about debugging this since the only error I get complains about something that the other server accepts.

Apparently a configuration in SELinux was preventing the session from being saved. This was proven by using the following command in a shell:

setenforce 0

and then testing the sessions again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM