P
P
Phantaminuum2016-11-09 18:32:39
PHP
Phantaminuum, 2016-11-09 18:32:39

Background tasks in PHP without client, alternative to cron?

The bottom line is this - there is some system (php-application), when a certain state is reached, a certain task in PHP is performed in it.
Example: there is a list of orders. Condition - if there are undelivered orders that have less than 30 minutes left before the estimated delivery time, then you need to send a notification to the courier that he may be late.
The simplest solution is to add a task to cron, run a script once a minute that will check the condition and do the job. Are there alternatives here in modern php?
I looked in the direction of queues and task servers, gearman, rabbitmq, but there the user case, as far as I understand, is a little different - there is a client that directly sends the task to the queue, but in my case there is no client, there is just a system state that triggers the task.
Another option is a php-daemon, in which the condition is checked in a loop and the script is put to sleep for a minute. But here you need to think about memory leaks, daemon restarts, etc.
Is banal cron really the best solution here?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Dart, 2016-11-09
@gobananas

Daemons in php have been and will be, google:
https://daemon.io/profyclub.ru/docs/274
Try
it, read reviews, etc. The problem with demons is that they need something else, and a monitoring system, whether the demon is running or not (the server was rebooted, consumed all the memory, just crashed, etc.) and all sorts of autorun systems in case of maintenance work in the DC.
The cron solution is usually simpler and more reliable, but only in one case: there is a guarantee that when the script is run by cron, the previous script has already completed its work, otherwise the server crash is just a matter of time or coincidence.

S
Sergey, 2016-11-09
@gangstarcj

What's wrong with cron? The ideal solution is not banal. Why reinvent the wheel?

X
xmoonlight, 2016-11-09
@xmoonlight

https://habrahabr.ru/post/129207/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question