【发布时间】:2020-05-23 18:05:20
【问题描述】:
我正在尝试在带有 Ubuntu 18.x 的 Vagrant Box 中部署旧版 Symfony 1.4(实际上是通过 FriendsOfSymfony1 [1] 获得的 Symfon 1.5)项目。我的 PHP 版本是 7.2.x(请参阅 [2])一切正常,网站加载,但我收到此错误(并且无法完成对旧网站的登录):
[Fri Feb 07 14:51:53.880189 2020] [php7:warn] [pid 2831] [client 10.0.2.2:63895] PHP 警告:session_start():会话 id 太长或包含非法字符,有效/home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/storage/sfSessionStorage.class.php 第 95 行中的字符是 az、AZ、0-9 和 '-,',引用者:http://127.0.0.1:8080/frontend_dev.php/registration/
[Fri Feb 07 14:51:53.880478 2020] [php7:warn] [pid 2831] [client 10.0.2.2:63895] PHP 警告:session_start():无法读取会话数据:文件(路径:/var /lib/php/sessions) 在 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/storage/sfSessionStorage.class.php 第 95 行,引用者:http://127.0.0.1:8080/frontend_dev.php/registration/
这里已经有讨论了:The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' 但是并没有解决我的问题。
相关代码sn-p(第95行)在这里:
设置session_id 的代码在同一个文件中,从第 52 行开始:
public function initialize($options = null)
{
$cookieDefaults = session_get_cookie_params();
$options = array_merge(array(
'session_name' => 'symfony',
'session_id' => null, // <=============== HERE
'auto_start' => true,
'session_cookie_lifetime' => $cookieDefaults['lifetime'],
'session_cookie_path' => $cookieDefaults['path'],
'session_cookie_domain' => $cookieDefaults['domain'],
'session_cookie_secure' => $cookieDefaults['secure'],
'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
'session_cache_limiter' => null,
), $options);
// initialize parent
parent::initialize($options);
This link 提到这是一个 PHP 7.1 问题(我有 PHP 7.2!?),并且您不能将 null 用作 session_id(就像上面的代码一样)。所以我改变了
'session_id' => null,
到
'session_id' => '',
然后我通过./symfony cc 清除缓存,然后重新启动 apache,但仍然:我收到 PHP 警告重新会话 ID。
Memcached 相关?
可能相关:查看遗留代码,我意识到会话存储是在我的factories.yml 文件中定义的,如下所示:
(snip)
storage:
class: sfCacheSessionStorage
param:
session_name: prx
cache:
class: sfMemcacheCache #[required] define the cache strategy
param:
servers: # Array of servers
localserver:
host: localhost # hostname or IP of mamcache server
port: 11211 # default memcache port
(snip)
Memcached 已安装并正在运行:
vagrant@ubuntu-bionic:~/swdev$ ps aux | grep -i memc
memcache 1002 0.0 0.3 424764 3036 ? Ssl 13:50 0:01 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid
vagrant 3289 0.0 0.1 13136 1108 pts/0 S+ 15:42 0:00 grep --color=auto -i memc
脚注
[1] 我使用的是来自 FriendsOfSymfony1 的更新,而不是 Symfony 1.4
https://github.com/FriendsOfSymfony1/symfony1
[2] PHP 版本
PHP 7.2.24-0ubuntu0.18.04.2
【问题讨论】: