IMHO, you should not go along this route. Http requests should be kept as short as possible to improve usability.
If some kind of “heavy processing” needs to be done, you can “paint” it using some kind of queue. A separate process / daemon on the server can pick up these tasks from the queue for their execution. The http application can then check to see if such a job continues to be processed / has been started / completed.
There are many libraries to facilitate this: Gearman , ØMQ , RabbitMQ , etc.
Http requests are not suitable for lengthy operations, so when trying to perform all kinds of problems :)
UPDATE
If you cannot use libraries on the server (for example, Gearman, etc.), you can create your own queue based on files or db, press "commands" in the queue from your application and have a cronjob read this queue and complete these tasks .
Jasper N. Brouwer
source share