php7 的 zend 会话数据库错误
error in zend session database for php7
我的应用程序需要使用数据库而不是文件来进行会话管理。
我的应用程序基于 Zend Framework 1.12.17、php 5.6.25,实际上是在 wampserver
上
那是我的config.ini
resources.session.use_only_cookies = true
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000
resources.session.gc_probability = 1
resources.session.gc_divisor = 100
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "app_session"
resources.session.saveHandler.options.primary = "id"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
当我想升级php到php7.0.10时,出现警告
Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (D:\wamp\www\myapp\top\session) in D:\wamp\www\myapp\top\library\versions\ZendFramework-1.12.17-minimal\library\Zend\Session.php on line 732
我正在寻找这个问题的根源。你有什么想法吗?
非常感谢
2016 年 9 月,Zend Framework 1 is reached EOL(停产)。这意味着它不会再改进了。代码库太旧,无法与 PHP 7.
配合使用
无论如何,你至少有两个选择:
- 在您的服务器上并行降级或 运行 PHP 5.6 以支持古老的 ZF1 应用程序。
- 通过将 DbTable 处理程序扩展为 suggested here,编写您自己的会话保存处理程序。
除了 edigus 的回答之外,这里还有一个扩展保存处理程序的简单实现:
<?php
require_once 'Zend/Session/SaveHandler/DbTable.php';
// NOTE: To fix an issue with Zend_Session_SaveHandler_DbTable on PHP 7 this class extends it and overrides the write
// method to simply always return true.
//
// See:
// See: https://github.com/zendframework/zf1/issues/665
// See: https://github.com/zendframework/zf1/pull/654
class My_Session_SaveHandler_DbTable extends Zend_Session_SaveHandler_DbTable
{
public function write($id, $data)
{
parent::write($id, $data);
return true;
}
}
问题写在这里:https://github.com/zendframework/zf1/issues/665#issue-127528467
Since an update that returns 0 but doesn't throw an exception was still a successful query with no error
因此函数 write
将 return false
而不是 true
,并且 PHP 7.0 需要 true
结果。
您可以通过在 Zend/Session/SaveHandler/DbTable.php
中更改来解决此问题:
if ($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) {
收件人:
if (is_int($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE)))) {
或者你也可以去掉if
,变成指令,保留$return = true;
。因为出错时,查询应该引发异常,所以任何 update()
没有异常都是好的。
我的应用程序需要使用数据库而不是文件来进行会话管理。 我的应用程序基于 Zend Framework 1.12.17、php 5.6.25,实际上是在 wampserver
上那是我的config.ini
resources.session.use_only_cookies = true
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000
resources.session.gc_probability = 1
resources.session.gc_divisor = 100
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "app_session"
resources.session.saveHandler.options.primary = "id"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
当我想升级php到php7.0.10时,出现警告
Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (D:\wamp\www\myapp\top\session) in D:\wamp\www\myapp\top\library\versions\ZendFramework-1.12.17-minimal\library\Zend\Session.php on line 732
我正在寻找这个问题的根源。你有什么想法吗?
非常感谢
2016 年 9 月,Zend Framework 1 is reached EOL(停产)。这意味着它不会再改进了。代码库太旧,无法与 PHP 7.
配合使用无论如何,你至少有两个选择:
- 在您的服务器上并行降级或 运行 PHP 5.6 以支持古老的 ZF1 应用程序。
- 通过将 DbTable 处理程序扩展为 suggested here,编写您自己的会话保存处理程序。
除了 edigus 的回答之外,这里还有一个扩展保存处理程序的简单实现:
<?php
require_once 'Zend/Session/SaveHandler/DbTable.php';
// NOTE: To fix an issue with Zend_Session_SaveHandler_DbTable on PHP 7 this class extends it and overrides the write
// method to simply always return true.
//
// See:
// See: https://github.com/zendframework/zf1/issues/665
// See: https://github.com/zendframework/zf1/pull/654
class My_Session_SaveHandler_DbTable extends Zend_Session_SaveHandler_DbTable
{
public function write($id, $data)
{
parent::write($id, $data);
return true;
}
}
问题写在这里:https://github.com/zendframework/zf1/issues/665#issue-127528467
Since an update that returns 0 but doesn't throw an exception was still a successful query with no error
因此函数 write
将 return false
而不是 true
,并且 PHP 7.0 需要 true
结果。
您可以通过在 Zend/Session/SaveHandler/DbTable.php
中更改来解决此问题:
if ($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) {
收件人:
if (is_int($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE)))) {
或者你也可以去掉if
,变成指令,保留$return = true;
。因为出错时,查询应该引发异常,所以任何 update()
没有异常都是好的。