Scenario: I have a php vagrant virtualbox server and a runnable jar that takes up to some minutes to run. Ideally, when the user goes to a certain route in my application, the server will start running said jar in the background so the user wont have to wait looking at a blank page, and, when the jar finishes executing, the page will automatically refresh(or the data in it) giving the user information that it got from the output of the jar.
Problem: So far, I managed to run the jar in the background using exec() function. I can even get the process id and check if it is still running or not. The problem i have is how can the php(per say) be notified when the jar stops running without blocking the normal execution? Is there even any way to do this? I've searched everywhere from laravel queues to forking the running process but nothing(as i understood) suits my needs.
EDIT: I think I may have found a solution but i would like to ask the community anyway. Say I use a javascript loop (with setInterval) after the page loads, and ,inside the loop, i make an ajax async request to the server asking if the process has ended, and, if so, bringing back the output of the jar and updating the web page with the new data. This would make for a very "pull" solution instead of the preferable "push" but I don't even know it the push approach is possible.
I'm still learning to code for web app and so this might be a silly question and for that I apologize. Please feel free to put me in the right path if this solution is completely off the rails.
Thanks in advance,