]> git.mxchange.org Git - friendica.git/blob - mod/worker.php
Merge remote-tracking branch 'upstream/develop' into 1611-frontend
[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\Config;
9 use \Friendica\Core\PConfig;
10
11 function worker_init($a){
12
13         if (!Config::get("system", "frontend_worker")) {
14                 return;
15         }
16
17         // We don't need the following lines if we can execute background jobs
18         if (function_exists("proc_open")) {
19                 return;
20         }
21
22         clear_worker_processes();
23
24         $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'worker.php'");
25
26         if ($workers[0]["processes"] > Config::get("system", "worker_queues", 4)) {
27                 return;
28         }
29
30         $a->start_process();
31
32         logger("Front end worker started: ".getmypid());
33
34         call_worker();
35
36         if ($r = poller_worker_process()) {
37
38                 // On most configurations this parameter wouldn't have any effect.
39                 // But since it doesn't destroy anything, we just try to get more execution time in any way.
40                 set_time_limit(0);
41
42                 poller_execute($r[0]);
43         }
44
45         call_worker();
46
47         $a->end_process();
48
49         logger("Front end worker ended: ".getmypid());
50
51         killme();
52 }