How to run a heavy php script?

There are several pages. Each of them come post the data. Further, based on the fact that it's post, you need to prepare the data using php and run the php function.

Once the script will work, it's in json saves everything he did in dB. Next, you need to play this json on the front.

The question is: in what order to properly handle the data? There is an option 1: when shall I come post any of the pages, on that page where he came to run the preloader and ajax to pass the post data to a file which will be heavy processing and when it will come to an end, to give various statuses. And if it is successful, do another ajax request to get the data from the history (take json) to remove preloader and start the front There is a option 2: when you come post at once on the same page where the front handle post and start the same heavy script (then you will not be able to make a preloader, because php runs first js) as all will work immediately without jerking the json from a dB to give it to js and he fulfills. The advantages of this is that no ajax requests and the data do not drag, they have calculated is on the page. The downside is that during treatment, people will see a blank page.

More is not see a way out. I will be glad for every answer!
March 19th 20 at 08:32
2 answers
March 19th 20 at 08:34
WebSocket + Service you don't even have PHP
March 19th 20 at 08:36
Raise the websocket connection, the heavy task is thrown into the queue when a task is processed, the websocket give the result to the client. Frameworks help you, if you are not able, on larval, for example, normally done.

Find more questions by tags Web DevelopmentPHP