Task execution in php in the background?

Good afternoon. Is the following scenario:

Clients send api (php) some data. It is necessary that the api is immediately returned and that data is taken and after answering the beginning of their treatment, to prevent the client from waiting for processing. How to do it?
October 8th 19 at 00:10
8 answers
October 8th 19 at 00:12
Solution
Classic method: data immediately after the adoption of written in raw form somewhere, for example in a special table view "date"+"user"+"serialized data". And then, every N minutes, cron runs this tablu, takes records and processes them.
Also think that cron + table will solve your problem better than hacks about multithreading in php. - Myrtis4 commented on October 8th 19 at 00:15
Stdit speaks the truth, we kind of problem and solved. It turns out not so superpose, all the same a no, and the queue Manager have to write. But you can live. - mackenzie.Mraz23 commented on October 8th 19 at 00:18
Did in the end, it turned out to be even easier, since data come from different sources, and the script of the cron processes all at once - cleveland commented on October 8th 19 at 00:21
Yes, this is a great option, although if the load is critical, can be this option a little change, personally, we write the data not in the database and in the file, so quick, and then crowns parses files. And the base do not pull once again, and the meaning is the same. - aniya.Kertzmann65 commented on October 8th 19 at 00:24
I have yet to load any, then we'll see. While what you write in MongoDB - cleveland commented on October 8th 19 at 00:27
In the file write is not safe in multi-threaded access (even if you append to the end if the block of data is large enough, it can be partially overwritten in the next request), so it is better to write to DB, more than enough any non-transactional database, myisam in mysql at least (if you create one record in one table per request)/ - jaunita commented on October 8th 19 at 00:30
When writing to a file you can use file locking (not working, however in Windows) or just write to different files if the data blocks are quite large. - patricia commented on October 8th 19 at 00:33
October 8th 19 at 00:14
October 8th 19 at 00:16
Well, I have to solve this problem I wrote a mini-daemon in PHP, which socket sent data for processing. There was another mini-project, so there is service on the signatures wrote — quite well worked.
Although gearman — a great option, I just didn't know about it) - Myrtis4 commented on October 8th 19 at 00:19
gearman a strong thing, thanks for the tip - mackenzie.Mraz23 commented on October 8th 19 at 00:22
October 8th 19 at 00:18
October 8th 19 at 00:20
via the command line with nohup
October 8th 19 at 00:22
October 8th 19 at 00:24
php_fpm and fastcgi_finish_request()
There's a caveat: if data processing is long, and the demands — often, the child processes fpm-a can not cope. Therefore, in most cases this is best done in a separate thread, which you can get on a separate server. - Myrtis4 commented on October 8th 19 at 00:27
October 8th 19 at 00:26
For such problems, there are managers of queues, such as RabbitMQ.

Find more questions by tags Web Development