Laravel 会话驱动程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17070851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:56:46  来源:igfitidea点击:

Laravel Session Drivers?

laravellaravel-4

提问by Mike Holler

Can anybody explain session drivers to me? A search on "laravel session drivers" revealed nothing about the different types. I ask because the following tutorial suggested using an array driver for a REST API, but I don't know why. Tutorial: https://speakerdeck.com/akuzemchak/simple-api-development-with-laravel?slide=62

有人可以向我解释会话驱动程序吗?对“laravel 会话驱动程序”的搜索没有发现有关不同类型的信息。我问是因为以下教程建议将数组驱动程序用于 REST API,但我不知道为什么。教程:https: //speakerdeck.com/akuzemchak/simple-api-development-with-laravel?slide =62

Here's the relevant section from app/config/session.php

这是 app/config/session.php 中的相关部分

/*
|--------------------------------------------------------------------------
| Default Session Driver
|--------------------------------------------------------------------------
|
| This option controls the default session "driver" that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: "native", "cookie", "database", "apc",
|            "memcached", "redis", "array"
|
*/

'driver' => 'native',

回答by radmen

It's quite easy. Driver defines where session data will be stored.

这很容易。驱动程序定义了会话数据的存储位置。

  • native- session will be handled by internal PHP rutines
  • cookie- session will be stored in cookies
  • database- session will be stored in database (by default in table sessions)
  • memcached/redis- use one of this daemons as a session storage
  • array- session will be stored in a plain array (it's handled by MockArraySessionStorage)
  • native- 会话将由内部 PHP 程序处理
  • cookie- 会话将存储在 cookie 中
  • database- 会话将存储在数据库中(默认在 table 中sessions
  • memcached/ redis- 使用此守护进程之一作为会话存储
  • array- 会话将存储在一个普通数组中(它由MockArraySessionStorage处理)

arraydriver means that session is only per request (stored during PHP runtime), and after that it disappears :)

array驱动程序意味着会话仅针对每个请求(在 PHP 运行时存储),之后它就会消失:)