How to implement deferred execution (not)scheduled tasks in PHP?

0 like 0 dislike
20 views
General concept: user came, said what he had to do and left. In his absence, the task runs periodically - until then, until you get the end result after the task is deleted.
The first thing that came to mind is cron. Actually -
And it turns out that you need using PHP to run cron in order to run PHP)

Questions:
1. In General in this direction to dig?)
2. You know any human PHP library for working with cron?
3. Is it permissible to keep the task queue in the database and apply it for their condition, retrieving, modifying, deleting it?

PS Frameworks in the project are not used.
by | 20 views

3 Answers

0 like 0 dislike
To use Cron you don't need the library, it's all very simple - crowns at a certain time to do something, anything. In your case it needs to launch your script or group of scripts. You just need to properly arrange the logic in a console controller.

As an example, the entry in Crontab-e looks like this:
> */5 * * * * / usr/bin/php /home/www/project/path/to/script.php --some=param

The whole logic of the script, of course, on you.

But Kron is very limited, not suitable for something complicated and special, or when task a whole lot about they are very heavy. There are more, and wrote other commentators, brokers queues - RabbitMQ, Gearman and others. These things can run tasks in the background, outside the main workflow. Based on them are built such wonderful things as CommandBus. But it is at times difficult chart.
by
0 like 0 dislike
Well, what confuses you in Cron?

Aim script on CZK(e.g. every 10 minutes). It checks the task from the database, and if there is a free, marks it that it is "in" begins to execute, and stores the result back in the database. If the result is successful, marks the task complete.
by
0 like 0 dislike
Queue php.net/manual/en/class.ds-queue.php

look in Google there are many examples of implementation on request "php queue example"

after the implementation it would also be good turn to put under the control of supervisor supervisord.org

PS: the package for cron https://github.com/peppeocchi/php-cron-scheduler
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked Apr 14, 2019 by YardalGedal
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
33,963 users