从php5.6升级php7.1,报错

 Warning: session_start(): Failed to read session data: user (path: )

 Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /datas/htdocs/test.php:)

方案:如果是自己写了 session 处理类,继承了 SessionHandlerInterface 接口,在 PHP71 中要保证 read 方法,返回的是一个 string,其他类型都会报错。

比如我的情况,在读不到的时候返回的是 false,在以前版本的 PHP 中,无不良表现,现在要改成返回空字符串。

[转载]Failed to read session data On PHP 7.1-LMLPHP

转自:https://segmentfault.com/a/1190000009603677

---------------------------------------------------------------2017-08-24------------------------------------------------------------------------

1、abstract public bool SessionHandlerInterface::write ( string $session_id , string $session_data )

返回值不是bool时,报错:

E_WARNING:session_write_close(): Session callback expects true/false return value

E_WARNING:session_write_close(): Failed to write session data using user defined save handler. (session.save_path: )

2、出现错误:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /datas/htdocs/root/swoole.php:67)

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /datas/htdocs/root/swoole.php:67)

需要修改对应配置:

ini_set('session.cache_limiter', false);
ini_set('session.use_cookies', false);

PS:参照手册(session.cache_limiter 指定会话页面所使用的缓冲控制方法(none/nocache/private/private_no_expire/public)。默认为 nocache。)设置为none时依旧报错

05-25 23:09