php7 - 自定义 SessionHandler 引发 session_write_close() 警告
php7 - Custom SessionHandler raises session_write_close() warning
我将我的项目从 php5.6
升级到 php7.0
,并且不时收到关于 session_write_close()
的 php 警告,显示我的临时文件夹的正确路径.
我的项目使用自定义数据库会话处理程序,它与旧 php 版本完美配合。
错误如下:
Warning: Unknown: Failed to write session data (user). Please verify
that the current setting of session.save_path is correct (C:\my\path)
in Unknown on line 0
这是我的 write() 函数:
/**
* @param string $id
* @param string $data
* @return bool
* @throws Zend_Db_Adapter_Exception
*/
public function write($id, $data)
{
$dateTime = date('Y-m-d H:i:s');
$newDateTime = date('Y-m-d H:i:s', strtotime($dateTime . sprintf(' + %s seconds', $this->getMaxLifetime())));
$sessionValues = array("id" => $id, "expires_at" => $newDateTime, "session_data" => $data);
$sel = new Zend_Db_Select($this->_zdb);
$sel->from(self::TABLE_NAME, array('id'))
->where('id = ?', $id);
$sessionExists = (bool)$this->_zdb->fetchOne($sel);
if($sessionExists) {
$result = $this->_zdb->update(self::TABLE_NAME, $sessionValues, array('id = ?' => $id));
} else {
$result = $this->_zdb->insert(self::TABLE_NAME, $sessionValues);
}
if($result) {
return true;
} else {
return false;
}
}
有什么想法可以解决吗?
感谢
好的,我终于找到了解决方案:
我的自定义会话处理程序中的我的数据库适配器 returns 会话更新时 0 table 不更新任何值。
我在 write() 函数中返回了我的查询结果。
The SessionHandlerInterface::write() function raises this warning in case it returns false.
也许这对其他人也有帮助。
我将我的项目从 php5.6
升级到 php7.0
,并且不时收到关于 session_write_close()
的 php 警告,显示我的临时文件夹的正确路径.
我的项目使用自定义数据库会话处理程序,它与旧 php 版本完美配合。
错误如下:
Warning: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (C:\my\path) in Unknown on line 0
这是我的 write() 函数:
/**
* @param string $id
* @param string $data
* @return bool
* @throws Zend_Db_Adapter_Exception
*/
public function write($id, $data)
{
$dateTime = date('Y-m-d H:i:s');
$newDateTime = date('Y-m-d H:i:s', strtotime($dateTime . sprintf(' + %s seconds', $this->getMaxLifetime())));
$sessionValues = array("id" => $id, "expires_at" => $newDateTime, "session_data" => $data);
$sel = new Zend_Db_Select($this->_zdb);
$sel->from(self::TABLE_NAME, array('id'))
->where('id = ?', $id);
$sessionExists = (bool)$this->_zdb->fetchOne($sel);
if($sessionExists) {
$result = $this->_zdb->update(self::TABLE_NAME, $sessionValues, array('id = ?' => $id));
} else {
$result = $this->_zdb->insert(self::TABLE_NAME, $sessionValues);
}
if($result) {
return true;
} else {
return false;
}
}
有什么想法可以解决吗?
感谢
好的,我终于找到了解决方案:
我的自定义会话处理程序中的我的数据库适配器 returns 会话更新时 0 table 不更新任何值。
我在 write() 函数中返回了我的查询结果。
The SessionHandlerInterface::write() function raises this warning in case it returns false.
也许这对其他人也有帮助。