]> git.mxchange.org Git - friendica.git/blob - include/poller.php
Merge pull request #3907 from annando/worker
[friendica.git] / include / poller.php
1 <?php
2 use Friendica\App;
3 use Friendica\Core\Worker;
4 use Friendica\Core\Config;
5
6 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
7         $directory = dirname($_SERVER["argv"][0]);
8
9         if (substr($directory, 0, 1) != "/") {
10                 $directory = $_SERVER["PWD"]."/".$directory;
11         }
12         $directory = realpath($directory."/..");
13
14         chdir($directory);
15 }
16
17 require_once("boot.php");
18
19 function poller_run($argv, $argc) {
20         global $a;
21
22         if (empty($a)) {
23                 $a = new App(dirname(__DIR__));
24         }
25
26         require_once ".htconfig.php";
27         require_once "include/dba.php";
28         dba::connect($db_host, $db_user, $db_pass, $db_data);
29         unset($db_host, $db_user, $db_pass, $db_data);
30
31         Config::load();
32
33         // Check the database structure and possibly fixes it
34         check_db(true);
35
36         // Quit when in maintenance
37         if (Config::get('system', 'maintenance', true)) {
38                 return;
39         }
40
41         $a->set_baseurl(Config::get('system', 'url'));
42
43         load_hooks();
44
45         $run_cron = (($argc <= 1) || ($argv[1] != "no_cron"));
46         Worker::processQueue($run_cron);
47         return;
48 }
49
50 if (array_search(__file__, get_included_files()) === 0) {
51         poller_run($_SERVER["argv"], $_SERVER["argc"]);
52
53         Worker::unclaimProcess();
54
55         get_app()->end_process();
56
57         killme();
58 }