Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2KB

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