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