Reputation: 5597
I'm trying to add some variables to a Laravel Session just by using the Laravel SessionId. The reason for this is I'm trying to update the Session data from a remote source (Queue job) and have the client be able to retrieve this data with a AJAX get request. The job can be running for minutes or hours so I need a way to update the client accordingly.
The idea is I send the Laravel SessionId (via Session::getId()
) to the job, the job looks up the Session via the sessionId and dynamically pushes attributes to the session, while the client long polls via AJAX to a route on the main server that returns the attributes pushed to the session by the job, and then removes all the attributes that were just flushed to the client.
I'm also using the Redis cluster driver on Amazon ElastiCache if that helps.
From what I've seen so far, the only way to access a session is to use the Session
facade, which is a static class, I'm basically looking for something such as $session = SessionAccessor::findSessionById($sessionId)
or something to that effect.
Is this possible in Laravel?
Upvotes: 2
Views: 1510
Reputation: 60048
I'm not convinced you want to use a session for this. What happens if the session ends before the queued job etc. The session ID can change during the job etc.
What I would do is make a jobs
table or something - and have the logged in user ID and the job ID, along with a 'status'. Then the queued job simply updates the database table when it is finished.
Meanwhile your AJAX poll hits a route that checks the DB for the latest status.
Upvotes: 1