Answer the question
In order to leave comments, you need to log in
What is the best way to organize the execution of background tasks in php?
Hello. There is a certain time-consuming task: sending mail / sms to the user after his action. When the user performs an action (clicks on some button), you need to put the task into the background, and write to the user: "everything is fine, you will receive a letter soon." The method known to me: we save this task somewhere (in a database or a file) and once a minute we pull a special cron script. He will be responsible for such tasks. The downside is that the maximum wait time for a user will be 1 minute. This is critical. I read about queue servers: german, rabbit. On projects of what scale is it better to use them so that there is no situation "we shoot sparrows from a cannon"? How would you recommend solving the problem?
Answer the question
In order to leave comments, you need to log in
use rabbit, create a task to send emails, add it to rabbit and sleep well, everything will be done even if the server goes to reboot at that moment. + things like the task queue are good to horizontally scale if the load grows.
Ajax... when clicked, show the block/text "Everything is OK, the SMS is gone", hide the form (block submit, etc.) and access the send script, and no queues and waiting are needed
Letters are sent by postal service one by one. If there are many users, then letters will still arrive with a delay. Why not send emails immediately after pressing ? Why put them in a queue?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question