$start_timestamp = time(); $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); if (!init_connection($link)) { return; } // We disable stamp file, since it is of no use in a multiprocess update. // not really, tho for the time being -fox if (!make_stampfile('update_daemon.stamp')) { print "warning: unable to create stampfile"; } // Call to the feed batch update function // or regenerate feedbrowser cache if (rand(0, 100) > 30) { update_daemon_common($link); } else { $count = update_feedbrowser_cache($link); _debug("Feedbrowser updated, {$count} feeds processed."); purge_orphans($link, true); $rc = cleanup_tags($link, 14, 50000); _debug("Cleaned {$rc} cached tags."); _debug("Updating linked feeds..."); get_linked_feeds($link); } _debug("Elapsed time: " . (time() - $start_timestamp) . " second(s)"); db_close($link); // We are in a fork. // We wait a little before exiting to avoid to be faster than our parent process. sleep(1); unlink(LOCK_DIRECTORY . "/{$lock_filename}"); // We exit in order to avoid fork bombing. exit(0);
function housekeeping_common($debug) { expire_cached_files($debug); expire_lock_files($debug); expire_error_log($debug); $count = update_feedbrowser_cache(); _debug("Feedbrowser updated, {$count} feeds processed."); purge_orphans(true); $rc = cleanup_tags(14, 50000); _debug("Cleaned {$rc} cached tags."); PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", ""); }
function housekeeping_common($debug) { expire_cached_files($debug); expire_lock_files($debug); expire_error_log($debug); $count = update_feedbrowser_cache(); _debug("Feedbrowser updated, {$count} feeds processed."); purge_orphans(true); $rc = cleanup_tags(14, 50000); _debug("Cleaned {$rc} cached tags."); }
} // Try to lock a file in order to avoid concurrent update. if (!$lock_handle) { die("error: Can't create lockfile ({$lock_filename}). " . "Maybe another update process is already running.\n"); } if (isset($options["force-update"])) { _debug("marking all feeds as needing update..."); db_query("UPDATE ttrss_feeds SET last_update_started = '1970-01-01',\n\t\t\t\tlast_updated = '1970-01-01'"); } if (isset($options["feeds"])) { update_daemon_common(); housekeeping_common(true); PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); } if (isset($options["feedbrowser"])) { $count = update_feedbrowser_cache(); print "Finished, {$count} feeds processed.\n"; } if (isset($options["daemon"])) { while (true) { $quiet = isset($options["quiet"]) ? "--quiet" : ""; passthru(PHP_EXECUTABLE . " " . $argv[0] . " --daemon-loop {$quiet}"); _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); sleep(DAEMON_SLEEP_INTERVAL); } } if (isset($options["daemon-loop"])) { if (!make_stampfile('update_daemon.stamp')) { _debug("warning: unable to create stampfile\n"); } update_daemon_common(isset($options["pidlock"]) ? 50 : DAEMON_FEED_LIMIT);