Answer the question
In order to leave comments, you need to log in
How to implement continuous task execution in PHP?
Hello! There is a certain task (infinite loop) which should be carried out continuously.
The option to launch on the crown is not suitable, because. there is no way to predict how long a part of a task will take.
The application itself is on Laravel, so I think to use the queuing mechanism and Artisan. But if something happens in the process of execution, the queue will be interrupted.
How to proceed? I think to dig in the direction of PhpDaemon, but I have no idea how it works.
Answer the question
In order to leave comments, you need to log in
$file='/tmp/parser_status.lock';
if(!flock($lock_file = fopen($file, 'w'), LOCK_EX | LOCK_NB))
die("Already runninng\n");
Wouldn't this option work?
<?php
set_time_limit(0);
while (true) { ... }
Yes, then you need a daemon, dig towards pcntl_fork() and examples of its use
Just at the end of the program execution, in the same program, add it to the queue
Like this:
do_really_hard_work(params)
queue.enqueue(_FILE_)
I have a php process running in an endless loop grabbing tasks from gearman .
monit makes sure that the process does not fall off, and restarts it if something happens. By default, monit runs its checks once a minute - in which case this solution is hardly better than the simpler method suggested by @L3n1n
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question