使用 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.
我们尝试过的事情:
无论我们尝试过什么,会话都存储在磁盘上的/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 会话未保存在内存缓存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!