]> git.mxchange.org Git - friendica.git/blob - scripts/worker.php
ccf24b7b43dd005421f9410e24b592280e92a9f7
[friendica.git] / scripts / worker.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * @file scripts/worker.php
5  * @brief Starts the background processing
6  */
7
8 use Friendica\App;
9 use Friendica\Core\Config;
10 use Friendica\Core\Worker;
11
12 // Ensure that worker.php is executed from the base path of the installation
13 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
14         $directory = dirname($_SERVER["argv"][0]);
15
16         if (substr($directory, 0, 1) != "/") {
17                 $directory = $_SERVER["PWD"]."/".$directory;
18         }
19         $directory = realpath($directory."/..");
20
21         chdir($directory);
22 }
23
24 require_once "boot.php";
25 require_once "include/dba.php";
26
27 $a = new App(dirname(__DIR__));
28
29 require_once ".htconfig.php";
30 dba::connect($db_host, $db_user, $db_pass, $db_data);
31 unset($db_host, $db_user, $db_pass, $db_data);
32
33 Config::load();
34
35 // Check the database structure and possibly fixes it
36 check_db(true);
37
38 // Quit when in maintenance
39 if (Config::get('system', 'maintenance', true)) {
40         return;
41 }
42
43 $a->set_baseurl(Config::get('system', 'url'));
44
45 load_hooks();
46
47 $spawn = (($_SERVER["argc"] == 2) && ($_SERVER["argv"][1] == "spawn"));
48
49 if ($spawn) {
50         Worker::spawnWorker();
51         killme();
52 }
53
54 $run_cron = (($_SERVER["argc"] <= 1) || ($_SERVER["argv"][1] != "no_cron"));
55
56 Worker::processQueue($run_cron);
57
58 Worker::unclaimProcess();
59
60 Worker::endProcess();
61
62 killme();
63