我正在尝试使用 redis 作为运行 bref php 的 lambda 会话驱动程序。它按预期写入数据(我可以使用 redis-cli 看到它)并存储在 $_SERVER 上,但是当您刷新页面时,会话为空。我没有使用框架,只是纯 php。
这是当前的行为:
- 浏览器 cookie 正确(名称 PHPSESSID 和与 redis 中相同的 id)
- var_dump($_COOKIE) 显示预期信息
- session_start() 返回真
- var_dump($_SESSION) 刷新后为空
- var_dump(ini_get("session.save_handler")) 显示正确的值
- var_dump(ini_get("session.save_path")) 显示正确的值
- 我可以在 redis-cli 实时监视器上看到 php 正在获取正确的密钥
这是我的serverless.yml相关部分:
plugins:
- ./vendor/bref/bref
- ./vendor/bref/extra-php-extensions
functions:
api:
handler: index.php
description: ''
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-74-fpm}
- ${bref-extra:redis-php-74}
- 'arn:aws:lambda:us-west-2:844410403720:layer:database:7'
我的 php/conf.d/php.ini:
extension=redis.so
[Session]
session.save_handler = redis
session.save_path = "tcp://redis.mydomain:6379"
session.use_strict_mode = 0
session.use_cookies = 1
session.cookie_secure = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 54000
session.cookie_path = /
session.cookie_domain = .mydomain.abc
session.cookie_httponly = 1
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 50
session.gc_maxlifetime = 864000
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 900
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
它似乎被应用了,因为这是我的 phpinfo() 输出:
session.auto_start | Off | Off
session.cache_expire | 900 | 900
session.cache_limiter | nocache | nocache
session.cookie_domain | .mydomain.abc | .mydomain.abc
session.cookie_httponly | 1 | 1
session.cookie_lifetime | 54000 | 54000
session.cookie_path | / | /
session.cookie_samesite | no value | no value
session.cookie_secure | 1 | 1
session.gc_divisor | 50 | 50
session.gc_maxlifetime | 864000 | 864000
session.gc_probability | 1 | 1
session.lazy_write | On | On
session.name | PHPSESSID | PHPSESSID
session.referer_check | no value | no value
session.save_handler | redis | redis
session.save_path | tcp://mydomain.abc:6379 | tcp://mydomain.abc:6379
session.serialize_handler | php | php
session.sid_bits_per_character | 5 | 5
session.sid_length | 26 | 26
session.upload_progress.cleanup | On | On
session.use_cookies | 1 | 1
session.use_only_cookies | 1 | 1
session.use_strict_mode | 0 | 0
session.use_trans_sid | 0 | 0
$_COOKIE['PHPSESSID'] | the right and expected hash
$_SERVER['HTTP_COOKIE'] | PHPSESSID= the right and expected hash
我不知道我是否缺少任何配置。有谁看到出了什么问题?