M
M
Mir2015-10-25 18:32:12
linux
Mir, 2015-10-25 18:32:12

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

6 answer(s)
A
Artem Spiridonov, 2015-10-25
@mir546

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.

M
Mark Doe, 2015-10-25
@mourr

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

T
Timur Sergeevich, 2015-10-25
@MyAlesya

WEBSOCKET

J
JSmitty, 2015-10-25
@JSmitty

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).

O
OnYourLips, 2015-10-25
@OnYourLips

Queues and demons.

U
unst, 2015-10-26
@unst

Queues are well suited for the solution, as mentioned above. It's kind of like a cron that waits for tasks to run.
For php it is convenient to use gearman. Tasks are conveniently created, the worker is conveniently written, there are a lot of examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question