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