Laravel 5.4.36 session 没有保存成功问题

  • session使用注意点   

    工作中使用的是session默认的文件缓存  在使用过发现  session()->put("key","values")  发现  没有设置成功  最后翻源码发现是使用文件缓存时候需要使用save() 方法才能持久化到数据库中

   源码:vendor/laravel/framework/src/Illuminate/Session/Store.php

   

    /**
     * Save the session data to storage.
     *
     * @return bool
     */
    public function save()
    {
        $this->ageFlashData();

        $this->handler->write($this->getId(), $this->prepareForStorage(
            serialize($this->attributes)
        ));

        $this->started = false;
    }

由于使用文件缓存 因此write方法调用的源码:vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php

    /**
     * {@inheritdoc}
     */
    public function write($sessionId, $data)
    {
        $this->files->put($this->path.'/'.$sessionId, $data, true);

        return true;
    }

 

 

如果有什么问题或者疑问欢迎留言  

posted on 2018-02-09 23:54  Sunlight1992  阅读(316)  评论(0编辑  收藏  举报

导航