Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ufodisko's avatar
Level 10

Session data getting lost between requests

Hello everyone, I have a bug in my app on production server only, I am unable to reproduce it locally. The app is still under construction and I'm just testing the production server so the app is not really available to the public yet.

In my jewelry ecommerce app, I have a custom ring building multistep form where the user first selects a ring, then selects a diamond and finally adds this custom ring to the cart.

I am saving this selection in the session whether the user is logged in or logged out. I figured it would be easier to save it in the session than the database. The data has 2 big json objects: ring and diamond.

The issue begin on the production server when I select the ring, it gets added to the session and I see the request in the Network tab. but then as soon as I select the diamond on the next step of the form, the session data gets wiped out and the post request being made to /build/diamond returns error 400 Ring data not found in session so adding it to cart returns error 500 because the data is not present.

This behavior is also inconsistent, sometimes this error doesn't appear and I can select and add a custom ring to the cart normally. This is like 10% of the times but the rest of the 90% I get the error.

So I am really lost as to why this is happening. My only lead at the moment is Session Blocking. This is my only lead because my app is making 2 consecutive (but not concurrent) api requests to /build/ring to save the ring selection before making the request to /build/diamond so maybe this is being blocked by laravel.

  • The ring data is being successfully saved to the session initially.
  • However, when trying to save the diamond selection, the ring data is no longer present in the session. This is evident from the log.
  • When attempting to add the custom ring to the cart, both the ring and diamond data are null.

But why wouldn't it block it on local server as well?

I appreciate your help on this and if there's a better way to achieve what I want without using Session data, I'm willing to listen.

PS: On my local machine I'm using PHP8.2.12 but on the production server I'm using PHP8.2.22.

0 likes
6 replies
JussiMannisto's avatar

Which session driver are you using in production?

You should probably show how and where you're writing/reading session data.

ufodisko's avatar
Level 10

@JussiMannisto This

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null
JussiMannisto's avatar

@ufodisko Is the database sqlite or something else? If it's sqlite, does your web app have write access to the storage/database.sqlite file?

JussiMannisto's avatar

because my app is making 2 consecutive api requests to /build/ring to save the ring selection

I don't know why your app does this, but it might be the problem.

Session data is loaded at the start of the request and written out at the end of the request, both by the StartSession middleware. If the 2nd request is started before the 1st has written out its changes, the 2nd request doesn't get the changes made by the 1st. Any session changes made by the 1st request will therefore be discarded when the 2nd request writes out its session data.

This won't be an issue locally if you're using artisan serve. That uses the PHP development server which handles a single request at a time.

Session blocking might fix this issue. But you probably should eliminate the consecutive requests instead.

ufodisko's avatar
Level 10

@JussiMannisto I'm sorry I misspoke. Both requests to /build/ring are consecutive but they are many seconds apart. They are not concurrent. So maybe my initial thinking about Session Blocking is incorrect.

Please or to participate in this conversation.