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.

62 lines
1.4 KiB

11 years ago
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * @file bin/worker.php
  5. * @brief Starts the background processing
  6. */
  7. use Dice\Dice;
  8. use Friendica\App;
  9. use Friendica\BaseObject;
  10. use Friendica\Core\Config;
  11. use Friendica\Core\Update;
  12. use Friendica\Core\Worker;
  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. $dice = (new Dice())->addRules(include __DIR__ . '/../static/dependencies.config.php');
  28. BaseObject::setDependencyInjection($dice);
  29. $a = BaseObject::getApp();
  30. // Check the database structure and possibly fixes it
  31. Update::check($a->getBasePath(), true, $a->getMode());
  32. // Quit when in maintenance
  33. if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
  34. return;
  35. }
  36. $a->setBaseURL(Config::get('system', 'url'));
  37. $spawn = array_key_exists('s', $options) || array_key_exists('spawn', $options);
  38. if ($spawn) {
  39. Worker::spawnWorker();
  40. exit();
  41. }
  42. $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options);
  43. Worker::processQueue($run_cron);
  44. Worker::unclaimProcess();
  45. Worker::endProcess();