PHP 会话未保存在内存缓存中

2024-04-13php开发问题
6

本文介绍了PHP 会话未保存在内存缓存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

使用 Amazon Linux 在 AWS 上使用 php 5.4 运行应用程序.

Running an application using php 5.4 on AWS using the Amazon Linux.

PHP 版本为 PHP 5.4.28.从 AWS 存储库安装的 memcache 库是 php54-pecl-memcache-3.0.8-1.11.amzn1.x86_64

PHP version is PHP 5.4.28. memcache lib installed from the AWS repo is php54-pecl-memcache-3.0.8-1.11.amzn1.x86_64

我已经验证 php 正在使用/etc/php.ini:

I have verified that php is using /etc/php.ini:

[root@ip-xx.xx.xx.xx]# php -i | grep Config
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

设置显示我应该使用内存缓存:

The setting show that I should be using memcache:

[root@ip-10-40-17-119 etc]# grep "^session.save" php.ini
session.save_handler="memcache"
session.save_path="tcp://<elasticache-endpoint>:11211"

[root@ip-10-40-17-119 php.d]# php -i | grep session.save
session.save_handler => memcache => memcache
session.save_path => tcp://<elasicache-endpoint>:11211?persistent=1&weight=1&timeout=1&retry_interval=15 => tcp://<elasticache-endpoint>:11211?persistent=1&weight=1&timeout=1&retry_interval=15

我可以从盒子telnet到终点&端口并正确连接,因此实例能够连接到 memcached 服务器.

I can telnet from the box to the end point & port and connect properly, so the instance is able to connect to the memcached server.

我们尝试过的事情:

  • 我已经从 php.ini 文件中删除了 tcp://,这并没有什么不同 - 会话仍然保存在文件中.
  • 我们已从 session.save_handler="memcache" 更改为 session.save_handler="memcached"
  • 每次我们进行更改时,我们都会停止 httpd 服务器,然后重新启动它
  • 我们甚至尝试过重启服务器

无论我们尝试过什么,会话都存储在磁盘上的/var/lib/php/sessions 中.是我遗漏了什么,还是这是已知的 5.4 或 AWS 问题?

Regardless of what we've tried, sessions are stored on disk to /var/lib/php/sessions. Is there something I'm missing, or is this a known 5.4 or AWS issue?

推荐答案

好的,我们设法解决了问题.

OK, we managed to figure out the issue.

首先,我们创建了一个输出 phpinfo() 的简单页面.请注意,通过 Web 服务器运行它很重要 - 运行 php -i 不包括 apache 可能添加的任何覆盖.

First, we created a simple page that spit out phpinfo(). Note that it is important that you run this thru the web server - running php -i DOES NOT include any overrides that apache may add.

在会话部分下,输出列出了所有指令,以及本地值"和主值".

Under the session section, the output lists all the directives, and a "Local Value" and a "Master Value".

本地值有:

session.save_handler    files
session.save_path   /var/lib/php/session

虽然主价值观有:

session.save_handler    memcache
session.save_path   tcp://<endpoint>:11211

事实证明,在/etc/httpd/conf.d/php.conf 中默认安装了一个覆盖来指定文件.这似乎是 Redhat/CentOS/Fedora 的事情.

It turns out that there's an override installed by default in /etc/httpd/conf.d/php.conf that specifies the files. This appears to be a Redhat/CentOS/Fedora thing.

从 php.conf 中删除这些值修复了问题.

Removing those values from php.conf fixed the problem.

这篇关于PHP 会话未保存在内存缓存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17