Answer the question
In order to leave comments, you need to log in
How to fork a php process from a browser?
The user enters data that will be sent via AJAX to the server.
Until the server script completes the response to the user will not come.
It is necessary that the server script transmits the response, but at the same time continues to work for small (20-40 seconds) additional calculations.
Cron thought. But not good. calculations should be immediately after user input.
Answer the question
In order to leave comments, you need to log in
A script can run another script on a separate thread.
For example, if php starts sh
The snippet "> /dev/null 2>&1 &" will cause the starting script to not wait for the running script to complete.
php can also run php.
By the way, the script can generate another script. If you need ideas of this kind.
Move the calculations to a separate script with ignore_user_abort , and call it after user input. It will be executed even when the user closes the browser until it completes the task and exits itself
The easiest option is if you have PHP running through PHP-FPM (that's the default for nginx), that is, calling fastcgi_finish_request() , which will do exactly what you need - give a response to the web server, and the script will continue to work safely after this (but nothing can be sent to the browser).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question