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

emmatraversy's avatar

Will the Controller Persist? Ensuring Seamless Workflow Execution with Laravel

I've developed a workflow UI enabling users to trigger a sequence of steps. The backend is being developed on Laravel. It's designed to establish SSH connections to remote servers and execute commands.

My Problem: Upon clicking the play or run button, a controller in Laravel initializes the execution of these steps. At each step's conclusion, the controller determines the subsequent step and proceeds with the process.

Now, let's consider a scenario where a user closes their web browser during, say, the second step. Will the Laravel controller persist in executing subsequent steps, eventually reaching step 7—the workflow's end? Or will the closure of the web browser halt the execution flow, preventing the controller from progressing?

Moreover, I'm interested in ensuring continuous execution by the controller, irrespective of whether the user closes their web browser. What strategies or techniques can be employed within Laravel to achieve this seamless execution?

Your insights are greatly appreciated! Thank you.

0 likes
6 replies
Tray2's avatar

The short answer is NO, it will not persist, it will not even persist in the different steps. The controller object is destroyed as soon as the request has done it's part.

emmatraversy's avatar

@Tray2 Thank you for your reply, Could you give me a clue what's the best strategy if I want the user just initiate the workflow and then tasks run in background even when user closes the UI?

Snapey's avatar
Snapey
Best Answer
Level 122

@emmatraversy you could place all the steps as jobs on the queue, and probably in a batch

A big consideration is how you intend to report progress?

1 like
emmatraversy's avatar

@Snapey Thank you for your reply, To be honest which I had in mind was: Having a State data structure (for example consider a large JSON object) consist of whole steps and their progress data, which executeStep() will update after finishing each step and store in DB. Then in the UI I wanted to perform a xhr request every n second to an API route (which only returns the State data) to get the updated state and rerender the UI accordingly.

Is this reasonable to you?

Snapey's avatar

@emmatraversy yes, as long as you create some unique id and pass it into each job and also send back to the client so that they can all track the same piece of work.

1 like
emmatraversy's avatar

@Snapey Thank you very much for your replies.

I will dig in to creating Jobs. Thanks a lot

Please or to participate in this conversation.