]> git.mxchange.org Git - friendica.git/blob - bin/worker.php
Add Monolog
[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 use Friendica\App;
8 use Friendica\Core\Config;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Worker;
11 use Friendica\Core\Update;
12
13 // Get options
14 $shortopts = 'sn';
15 $longopts = ['spawn', 'no_cron'];
16 $options = getopt($shortopts, $longopts);
17
18 // Ensure that worker.php is executed from the base path of the installation
19 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
20         $directory = dirname($_SERVER["argv"][0]);
21
22         if (substr($directory, 0, 1) != '/') {
23                 $directory = $_SERVER["PWD"] . '/' . $directory;
24         }
25         $directory = realpath($directory . '/..');
26
27         chdir($directory);
28 }
29
30 require dirname(__DIR__) . '/vendor/autoload.php';
31
32 $logger = Logger::create('worker');
33
34 $a = new App(dirname(__DIR__), $logger);
35
36 // Check the database structure and possibly fixes it
37 Update::check(true);
38
39 // Quit when in maintenance
40 if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
41         return;
42 }
43
44 $a->setBaseURL(Config::get('system', 'url'));
45
46 $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
47
48 if ($spawn) {
49         Worker::spawnWorker();
50         exit();
51 }
52
53 $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
54
55 Worker::processQueue($run_cron);
56
57 Worker::unclaimProcess();
58
59 Worker::endProcess();