]> git.mxchange.org Git - friendica.git/blob - mod/worker.php
The central item fetch does work now and the API now uses these functions
[friendica.git] / mod / worker.php
1 <?php
2 /**
3  * @file mod/worker.php
4  * @brief Module for running the worker as frontend process
5  */
6
7 use Friendica\Core\Config;
8 use Friendica\Core\Worker;
9
10 function worker_init(){
11
12         if (!Config::get("system", "frontend_worker")) {
13                 return;
14         }
15
16         // We don't need the following lines if we can execute background jobs.
17         // So we just wake up the worker if it sleeps.
18         if (function_exists("proc_open")) {
19                 Worker::executeIfIdle();
20                 return;
21         }
22
23         Worker::clearProcesses();
24
25         $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'");
26
27         if ($workers[0]["processes"] > Config::get("system", "worker_queues", 4)) {
28                 return;
29         }
30
31         Worker::startProcess();
32
33         logger("Front end worker started: ".getmypid());
34
35         Worker::callWorker();
36
37         if ($r = Worker::workerProcess()) {
38
39                 // On most configurations this parameter wouldn't have any effect.
40                 // But since it doesn't destroy anything, we just try to get more execution time in any way.
41                 set_time_limit(0);
42
43                 $fields = ['executed' => DateTimeFormat::utcNow(), 'pid' => getmypid(), 'done' => false];
44                 $condition =  ['id' => $r[0]["id"], 'pid' => 0];
45                 if (dba::update('workerqueue', $fields, $condition)) {
46                         Worker::execute($r[0]);
47                 }
48         }
49
50         Worker::callWorker();
51
52         Worker::unclaimProcess();
53
54         Worker::endProcess();
55
56         logger("Front end worker ended: ".getmypid());
57
58         killme();
59 }