]> git.mxchange.org Git - friendica.git/blob - mod/worker.php
Merge remote-tracking branch 'upstream/develop' into item-delete
[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                 if (poller_claim_process($r[0])) {
44                         Worker::execute($r[0]);
45                 }
46         }
47
48         Worker::callWorker();
49
50         Worker::unclaimProcess();
51
52         Worker::endProcess();
53
54         logger("Front end worker ended: ".getmypid());
55
56         killme();
57 }