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.

60 lines
1.3KB

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