What you are asking for cannot be done using the HTTP protocol. Each request receives a response synchronously. Closest to achieving what you want:
The client sends the request, and the server immediately responds with the job ID, while it also starts the background job for this lengthy calculation.
The client can then query the server for status by sending the job ID to a new request. The answer is immediate again and contains the status of the work, such as "in progress", "completed", "failed", etc. The server can also return a percentage of progress that the client can use to display a progress bar.
You can also implement web sockets, but this requires a server and client with socket support.
source
share