actualize_script.php 2.9 KB

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