I came across this when trying to solve a similar problem: updating the progress of a long-term process on the client side.
The problem is this: when you make a request to the server, the session values ββare not written to the session store until the response is returned to the client. Basically the process is as follows:
CLIENT | SERVER | . send request ----|----> start processing | . | . | . | finish processing | write session values receive response <----|---- return response
What you do is something like this:
CLIENT | SERVER | . send request ----|----> start processing | . | (update session) | . | (update session) | . | (update session) | . | finish processing | write session values receive response <----|---- return response
But those calls (update session) on the server are ignored - they are not actually recorded in the session store. Therefore, when a client makes a call to your route to request a session value for progress, he receives nothing.
The solution is simple: write the meaning of progress elsewhere. I solved this a long time ago by writing a value to a file using file_put_contents . If I did this today, I would probably look at the redis server for better performance.
However, one note: if you decide to write the value somewhere else, you need to somehow associate the value with the session. Otherwise, other users will overwrite your value. For a simple project, I would probably use the value of the user ID (assuming that it will only process one thing at a time).
source share