PHP 7用户会话问题-无法初始化存储模块 [英] PHP 7 user sessions issue - Failed to initialize storage module

查看:346
本文介绍了PHP 7用户会话问题-无法初始化存储模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP 7.0中使用各种PHP框架会话驱动程序时,存在一个错误.我最初在使用CodeIgniter数据库驱动程序时遇到此问题,并假定它是CodeIgniter问题,但此后在多个会话驱动程序和多个框架上都遇到了此问题.在这一点上,我已经安全地得出结论,会话驱动程序的类型无关紧要-似乎是随机的,应用程序将崩溃,并且日志(我已经尝试过Apache和php-fpm + nginx)填充了以下内容:

A bug exists when using various PHP framework session drivers with PHP 7.0. I initially experienced this issue while using the CodeIgniter database driver and assumed it was a CodeIgniter issue but have since experienced it on multiple sessions drivers and multiple frameworks. At this point I have safely concluded that the type of session driver is irrelevant - seemingly at random, the application will crash and the logs (I've tried both Apache and php-fpm + nginx) fill up with the following:

PHP致命错误:session_start():无法初始化存储 模块:用户(路径:[无论我的php.ini路径中有什么])

PHP Fatal error: session_start(): Failed to initialize storage module: user (path: [whatever I have in my php.ini path])

我正在使用的驱动程序不使用php.ini中设置的值,并且不管我是否将session.save_handler设置为php.ini中的文件,redis等,并且不考虑我设置的路径(Redis服务器,如果redis ,启用了文件的完全可写文件夹),则会发生错误.除非在框架外部的php文件中调用本地"session_start()",否则不应单击此处的路径.另外,在框架外部调用"session_start()"也可以正常工作……因此,很明显,PHP可以访问路径.好像在某个时候,会话驱动程序变成了框架驱动程序与php.ini中设置的任何内容的混合体.错误消息始终具有session.save_handler的用户",因此显然不是从php.ini中提取...而是路径.为什么会这样呢?这是在您经历之前难以描述的问题之一……并且很难重现,因为即使在数百次会话中一切都看起来可以正常工作(直到突然停止工作).重新启动Apache也不能解决问题-这里有很多问题,我最终只是重新启动机器以避免停机.显然,PHP 7机器现在将从负载均衡器的旋转中退出……但是我希望现在能解决问题.

The drivers I am using do not use the values set in php.ini and regardless of whether I set the session.save_handler to files, redis, etc in php.ini and regardless of the path I set (Redis server if redis, fully-writable folder with files enabled) the errors occur. The path here should never be hit unless a native "session_start()" is called in a php file outside of the framework. Also, calling "session_start()" outside of the framework works fine... so clearly PHP can access the path. It's as if at some point, the sessions driver becomes a hybrid of the framework driver and whatever is set in php.ini. The error message always has "user" for the session.save_handler so obviously that's not being pulled from php.ini... but the path is. Why would this be happening? This is one of those issues that is difficult to describe until you have experienced it... and it's difficult to reproduce because everything seems to work fine even for hundreds of sessions (until it suddenly stops working). Restarting Apache does not correct the issue either - there are a number of issues at play here and I end up just rebooting the machine to avoid the downtime. Obviously the PHP 7 machine will be pulled out of the load balancer rotation now... but I was hoping to have things figured out by now.

我在PHP 7.0 RC5,RC6和& RC8可以自己编译,也可以在Ubuntu 15.10 Wily(7.0.0-2 + deb.sury.org〜wily + 1)上编译最新的OndřejSurýPPA.我在CodeIgniter& Symfony,无论框架中使用的驱动程序类型(文件,数据库,redis)还是php.ini中设置的session.save_handler(都应该在此处无关紧要,但应该以为提及)都遇到了问题).我一直在尝试组合并把它们扔掉,这个问题每一次都会发生(有时需要12个小时以上的时间,具体取决于网站的访问量).

I have experienced the issue with PHP 7.0 RC5, RC6, & RC8 compiled on my own as well as the latest Ondřej Surý PPA on Ubuntu 15.10 Wily (7.0.0-2+deb.sury.org~wily+1). I have experienced the issue on CodeIgniter & Symfony, and have experienced the issue regardless of the type of driver used in the framework (files, database, redis) or the session.save_handler set in php.ini (which, again, should be irrelevant here but just thought it should be mentioned). I keep trying combinations and throwing things out in the wild and this issue happens every single time (sometimes it takes 12+ hours depending on the traffic to the website).

感谢您提供的任何帮助!我愿意接受建议,并且乐于尝试任何东西.

Thanks for any help you can provide! I'm open to suggestions and willing to try anything at this point.

推荐答案

函数_open应该返回true以避免发生此错误.

function _open should return true to avoid this error.

无论我们使用数据库还是文件,都不能为null或为空.

It can not be null or empty whatever we use either database or file.

当我们使用数据库存储会话数据时,我们将其保留为空白或不返回布尔值.这是导致此错误的主要原因.

When we use database to store session data, we keep it blank or no Boolean return. that is the main reason for this error.

class session_handler
{
    public function __construct()
    {
        session_set_save_handler(
            array($this, "_open"),
            array($this, "_close"),
            array($this, "_read"),
            array($this, "_write"),
            array($this, "_destroy"),
            array($this, "_gc")
        );
    }

    public function _open($savePath, $sessionId)
    {
        return true;
    }

    public function _close() {  }    
    public function _read($id) {  }
    public function _write($id, $data) {  }
    public function _destroy($id) {  }
    public function _gc($max) {  }
}

仅适用于PHP7.我不知道它是否是错误.

It is only for PHP 7. I do not know it is a bug or not.

这篇关于PHP 7用户会话问题-无法初始化存储模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆