You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-essentials/01-routing.md
+30-4Lines changed: 30 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -732,22 +732,48 @@ public function store(Todo $todo): Redirect
732
732
733
733
### Session configuration
734
734
735
-
Currently, there's only a built-in file session driver. More drivers are to be added in the future. By default, the session will stay valid for 10 hours, which you can overwrite by creating a `session.config.php` file:
735
+
Tempest supports file and database-based sessions, the former being the default option. Sessions can be configured by creating a `session.config.php` file, in which the expiration time and the session driver can be specified.
736
+
737
+
#### File sessions
738
+
739
+
When using file-based sessions, which is the default, session data will be stored in files within the specified directory, relative to `.tempest`. You may configure the path and expiration duration like so:
736
740
737
741
```php app/Config/session.config.php
738
-
<?php
739
742
use Tempest\Http\Session\Config\FileSessionConfig;
740
743
use Tempest\DateTime\Duration;
741
744
742
745
return new FileSessionConfig(
743
-
path: 'sessions', // The path is relative to the project's cache folder
746
+
expiration: Duration::days(30),
747
+
path: 'sessions',
748
+
);
749
+
```
750
+
751
+
#### Database sessions
752
+
753
+
Tempest provides a database-based session driver, particularly useful for applications that run on multiple servers, as the session data can be shared across all instances.
754
+
755
+
Before using database sessions, a dedicated table is needed. Tempest provides a migration, which may be installed in your project using its installer:
756
+
757
+
```sh
758
+
./tempest install sessions:database
759
+
```
760
+
761
+
This installer will also suggest creating the configuration file that sets up database sessions, with a default expiration of 30 days:
762
+
763
+
```php app/Sessions/session.config.php
764
+
use Tempest\Http\Session\Config\DatabaseSessionConfig;
765
+
use Tempest\DateTime\Duration;
766
+
767
+
return new DatabaseSessionConfig(
744
768
expiration: Duration::days(30),
745
769
);
746
770
```
747
771
748
772
### Session cleaning
749
773
750
-
Outdated sessions should occasionally be cleaned up. Tempest comes with a built-in command to do so: `tempest session:clean`. This command makes use of the [scheduler](/2.x/features/scheduling). If you have scheduling enabled, it will automatically run behind the scenes.
774
+
Sessions expire based on the last activity time. This means that as long as a user is actively using your application, their session will remain valid.
775
+
776
+
Outdated sessions must occasionally be cleaned up. Tempest comes with a built-in command to do so, `session:clean`. This command makes use of the [scheduler](/2.x/features/scheduling). If you have scheduling enabled, it will automatically run behind the scenes.
0 commit comments