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);
     }
 }
 // We wait a little time before the next fork, in order to let the first fork
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.");
}
        _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);
    if (!isset($options["pidlock"]) || $options["task"] == 0) {
        housekeeping_common(true);
    }
    PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
}
if (isset($options["cleanup-tags"])) {
    $rc = cleanup_tags(14, 50000);
    _debug("{$rc} tags deleted.\n");
}
if (isset($options["indexes"])) {
    _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
    _debug("Type 'yes' to continue.");
    if (read_stdin() != 'yes') {
        exit;
    }
    _debug("clearing existing indexes...");
    if (DB_TYPE == "pgsql") {
        $result = db_query("SELECT relname FROM\n\t\t\t\tpg_catalog.pg_class WHERE relname LIKE 'ttrss_%'\n\t\t\t\t\tAND relname NOT LIKE '%_pkey'\n\t\t\t\tAND relkind = 'i'");
    } else {
        $result = db_query("SELECT index_name,table_name FROM\n\t\t\t\tinformation_schema.statistics WHERE index_name LIKE 'ttrss_%'");
    }
    while ($line = db_fetch_assoc($result)) {
Example #4
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", "");
}
Example #5
0
 static function updaterandomfeed_real($dbh)
 {
     // Test if the feed need a update (update interval exceded).
     if (DB_TYPE == "pgsql") {
         $update_limit_qpart = "AND ((\n                    ttrss_feeds.update_interval = 0\n                    AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)\n                ) OR (\n                    ttrss_feeds.update_interval > 0\n                    AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)\n                ) OR ttrss_feeds.last_updated IS NULL\n                OR last_updated = '1970-01-01 00:00:00')";
     } else {
         $update_limit_qpart = "AND ((\n                    ttrss_feeds.update_interval = 0\n                    AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)\n                ) OR (\n                    ttrss_feeds.update_interval > 0\n                    AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)\n                ) OR ttrss_feeds.last_updated IS NULL\n                OR last_updated = '1970-01-01 00:00:00')";
     }
     // Test if feed is currently being updated by another process.
     if (DB_TYPE == "pgsql") {
         $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')";
     } else {
         $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))";
     }
     $random_qpart = sql_random_function();
     // we could be invoked from public.php with no active session
     if ($_SESSION["uid"]) {
         $owner_check_qpart = "AND ttrss_feeds.owner_uid = '" . $_SESSION["uid"] . "'";
     } else {
         $owner_check_qpart = "";
     }
     // We search for feed needing update.
     $result = $dbh->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id\n            FROM\n                ttrss_feeds, ttrss_users, ttrss_user_prefs\n            WHERE\n                ttrss_feeds.owner_uid = ttrss_users.id\n                AND ttrss_users.id = ttrss_user_prefs.owner_uid\n                AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'\n                {$owner_check_qpart}\n                {$update_limit_qpart}\n                {$updstart_thresh_qpart}\n            ORDER BY {$random_qpart} LIMIT 30");
     $feed_id = -1;
     require_once "rssfuncs.php";
     $num_updated = 0;
     $tstart = time();
     while ($line = $dbh->fetch_assoc($result)) {
         $feed_id = $line["id"];
         if (time() - $tstart < ini_get("max_execution_time") * 0.7) {
             update_rss_feed($feed_id, true);
             ++$num_updated;
         } else {
             break;
         }
     }
     // Purge orphans and cleanup tags
     purge_orphans();
     cleanup_tags(14, 50000);
     if ($num_updated > 0) {
         print json_encode(array("message" => "UPDATE_COUNTERS", "num_updated" => $num_updated));
     } else {
         print json_encode(array("message" => "NOTHING_TO_UPDATE"));
     }
 }