5
votes

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

Here's the relevant section from 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',
1

1 Answers

17
votes

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)

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