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.

66 lines
1.6KB

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