When I asked the question What is the solution for asynchronous processes in PHP? , basically what I had in mind was this question:
"Is there a way to complete a request from a client, but leave a process running in the same script that serves this client, such as a record in the database followed by an email?
I came to realize that thinking about the word "asynchronism" might not be the most correct approach, since I do not want parallel processes.
When a request is sent to a PHP script, all processing is done there, at the end of operations, the response is sent to the client. And the client (browser), in turn, is waiting for the execution of that process to end.
The question I asked earlier about asynchronous processes already has several answers on how to "dribble" this small PHP problem.
But what I would like to know is: Is there any way to send a response to the client when a request is made to a PHP script, but that same script continues to run on the server side until a long operation ?
For example:
gravar_dados_no_banco();
// Envia a resposta pro navegador
// Porém ele não precisa mais esperar o término desse script
echo json_encode(['status' => true]);
// Depois da resposta acima
// Faço algumas operações demoradas
// Que não serão "esperadas" pelo navegador
sleep(3);
mandar_email_pro_admin();
atualizar_todos_webservices();