【问题标题】:PHP Memcache failed to write session dataPHP Memcache 无法写入会话数据
【发布时间】:2015-11-02 17:07:22
【问题描述】:

我有两台服务器,我正在为会话安装 PHP Memcache。一个工作没有问题,另一个我一直在努力。服务器具有相同的 php 和 libs 版本、相同的操作系统 (RHEL 6.7)、不同的内存大小、不同的磁盘空间,但我无法缩小问题的范围。

我编写了一个小的 php 文件来创建会话并尝试 session_write_close()。对于一个系统,我没有收到任何错误,并且会话与 memcache 保持一致,对于另一个系统,我得到了这个:

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)

这是我的 /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"

这是我的 /etc/sysconfig/memcached

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

同样,这些文件在我的两台服务器之间是相同的,一个有效,一个无效。我什至不确定如何调试它,因为我得到的唯一错误是抱怨其他服务器接受的东西。

【问题讨论】:

    标签: php linux memcached


    【解决方案1】:

    显然 SELinux 中的配置阻止了会话被保存。这已通过在 shell 中使用以下命令得到证明:

    setenforce 0
    

    然后再次测试会话。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2015-02-28
      • 2016-10-09
      • 2015-04-02
      • 2011-05-14
      相关资源
      最近更新 更多