forgotten $
[friendica.git/.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 use Friendica\Core\L10n;
13
14 // Get options
15 $shortopts = 'sn';
16 $longopts = ['spawn', 'no_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 $lang = L10n::getBrowserLanguage();
38 L10n::loadTranslationTable($lang);
39
40 // Check the database structure and possibly fixes it
41 check_db(true);
42
43 // Quit when in maintenance
44 if (Config::get('system', 'maintenance', false, true)) {
45         return;
46 }
47
48 $a->set_baseurl(Config::get('system', 'url'));
49
50 Addon::loadHooks();
51
52 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
53
54 if ($spawn) {
55         Worker::spawnWorker();
56         killme();
57 }
58
59 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
60
61 Worker::processQueue($run_cron);
62
63 Worker::unclaimProcess();
64
65 Worker::endProcess();
66
67 killme();