php - calculation take time to complete, but i want to make it processing in background and user can visit another page?
one text
Solution:
The approach explained here uses Javascript
and PHP
in combination to solve the problem.
First Step, Make an AJAX request from the browser(with Javascript) to the backend PHP calculation logic. You can seperate the calculation script which will not render the HTML to show full web page. It will send a JSON response with message log to the AJAX request.
Second Step, Save the AJAX request state(running|completed) on browser local storage. It is necessary to make the call persistant across multiple page visits.
Third Step, In your PHP calcualation script you have to save the state(running|completed) of the calculation script. It is necessary to track the progress of the calculation.
Fourth Step, If the user is in the same page for the duration of the calculation script to run then the AJAX request can handle the calculation complete notification. Otherwise check if a request has already been made(from local storage data that you have saved in the Second Step). If yes then retrive the data from the data base(that you have saved with PHP on Step Three).
Hope that explains the process.
Source