---
title: "Discussion on \"Reading the Laravel Session Without Saving It\" | Hashnode"
description: "Discussion on \"Reading the Laravel Session Without Saving It\". Laravel saves the whole session at the end of every web request, even when nothing changed. Here is what that means when two requests overlap, and how to let a request read the session without writing it back."
url: "https://hashnode.com/posts/reading-laravel-session-without-saving/6ace74f8ccae093f439d6a5b"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Reading the Laravel Session Without Saving It](https://ubeyd.dev/reading-laravel-session-without-saving?utm_source=hashnode&utm_medium=feed)

Laravel saves the whole session at the end of every web request, even when nothing changed. Here is what that means when two requests overlap, and how to let a request read the session without writing it back.

Oct 13 · 9 min read · ubeyd.dev  
Read the article

-   [#laravel](https://hashnode.com/tag/laravel)
-   [#php](https://hashnode.com/tag/php)
-   [#sessions](https://hashnode.com/tag/sessions)
-   [#debugging](https://hashnode.com/tag/debugging)
-   [#web-development](https://hashnode.com/tag/web-development)

## Written by

[Ubeydullah Keleş](https://hashnode.com/@ubeyd)

@ubeyd · Abidjan, Ivory Coast

  
[View profile](https://hashnode.com/@ubeyd)

Laravel Developer

## Responses 2

Markdown supported · ⌘↵ to post

[Kamran Khan](https://hashnode.com/@kamrankhandev)

[Oct 16](https://hashnode.com/posts/reading-laravel-session-without-saving/6ace74f8ccae093f439d6a5b/comment/6ad2280a01c4b34da625d01d)

The clearest writeup of this race I've read — "every request in the web group is a writer" is the sentence that makes the whole thing click.

One caveat I'd add to your honest-details list: never put this middleware on a route that regenerates or invalidates the session. `logout()` calls `$this->session->invalidate()`, which destroys the old session row and writes a fresh empty one — with the `NullSessionHandler`, both the destroy and the write are discarded. The browser gets the new session cookie, but the old session stays valid server-side for its full lifetime. Logout would look successful while the session quietly survives.

Same applies anywhere you call `regenerate()`. The middleware is strictly for read-only routes; anything that mutates session identity needs the real handler. Worth a line in the post, because "apply it broadly to stop races" is the tempting misreading.

[Ubeydullah Keleş](https://hashnode.com/@ubeyd)

[Oct 16](https://hashnode.com/posts/reading-laravel-session-without-saving/6ace74f8ccae093f439d6a5b/comment/6ad2280a01c4b34da625d01d#reply-6ad229ef222f533a6f24122f)

Thanks for your addition [Kamran Khan](https://hashnode.com/@kamrankhandev "Kamran Khan")
