actualize_script.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env php
  2. <?php
  3. require(__DIR__ . '/../cli/_cli.php');
  4. session_cache_limiter('');
  5. ob_implicit_flush(false);
  6. ob_start();
  7. $begin_date = date_create('now');
  8. // Set the header params ($_GET) to call the FRSS application.
  9. $_GET['c'] = 'feed';
  10. $_GET['a'] = 'actualize';
  11. $_GET['ajax'] = 1;
  12. $_GET['force'] = true;
  13. $_SERVER['HTTP_HOST'] = '';
  14. $app = new FreshRSS();
  15. FreshRSS_Context::initSystem();
  16. FreshRSS_Context::$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  17. define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_syslog_enabled);
  18. /**
  19. * Writes to FreshRSS admin log, and if it is not already done by default,
  20. * writes to syslog (only if simplepie_syslog_enabled in FreshRSS configuration) and to STDOUT
  21. */
  22. function notice($message) {
  23. Minz_Log::notice($message, ADMIN_LOG);
  24. // @phpstan-ignore-next-line
  25. if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) {
  26. syslog(LOG_NOTICE, $message);
  27. }
  28. // @phpstan-ignore-next-line
  29. if (defined('STDOUT') && !COPY_SYSLOG_TO_STDERR) {
  30. fwrite(STDOUT, $message . "\n"); //Unbuffered
  31. }
  32. }
  33. notice('FreshRSS starting feeds actualization at ' . $begin_date->format('c'));
  34. // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well
  35. echo 'Failed requirements!', "\n";
  36. performRequirementCheck(FreshRSS_Context::$system_conf->db['type']);
  37. ob_clean();
  38. echo 'Results: ', "\n"; //Buffered
  39. // Create the list of users to actualize.
  40. // Users are processed in a random order but always start with default user
  41. $users = listUsers();
  42. shuffle($users);
  43. if (FreshRSS_Context::$system_conf->default_user !== '') {
  44. array_unshift($users, FreshRSS_Context::$system_conf->default_user);
  45. $users = array_unique($users);
  46. }
  47. $limits = FreshRSS_Context::$system_conf->limits;
  48. $min_last_activity = time() - $limits['max_inactivity'];
  49. foreach ($users as $user) {
  50. FreshRSS_Context::initUser($user);
  51. if (FreshRSS_Context::$user_conf == null) {
  52. notice('Invalid user ' . $user);
  53. continue;
  54. }
  55. if (!FreshRSS_Context::$user_conf->enabled) {
  56. notice('FreshRSS skip disabled user ' . $user);
  57. continue;
  58. }
  59. if (($user !== FreshRSS_Context::$system_conf->default_user) &&
  60. (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
  61. notice('FreshRSS skip inactive user ' . $user);
  62. continue;
  63. }
  64. FreshRSS_Auth::giveAccess();
  65. Minz_ExtensionManager::callHook('freshrss_user_maintenance');
  66. $app->init();
  67. notice('FreshRSS actualize ' . $user . '…');
  68. echo $user, ' '; //Buffered
  69. $app->run();
  70. if (!invalidateHttpCache()) {
  71. Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG);
  72. if (defined('STDERR')) {
  73. fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
  74. }
  75. }
  76. gc_collect_cycles();
  77. }
  78. $end_date = date_create('now');
  79. $duration = date_diff($end_date, $begin_date);
  80. notice('FreshRSS actualization done for ' . count($users) .
  81. ' users, using ' . format_bytes(memory_get_peak_usage(true)) . ' of memory, in ' .
  82. $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds.'));
  83. echo 'End.', "\n";
  84. ob_end_flush();