Index: feedapi.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feedapi/feedapi.module,v retrieving revision 1.23.2.119.2.80 diff -u -F^f -r1.23.2.119.2.80 feedapi.module --- feedapi.module 24 Sep 2009 22:54:44 -0000 1.23.2.119.2.80 +++ feedapi.module 25 Sep 2009 00:03:33 -0000 @@ -711,11 +711,11 @@ function feedapi_cron() { $now = time(); $process = 0; // The counter process will be > 0 if we've selected less feeds - while (!$process && feedapi_cron_time()) { + while (!$process && feedapi_time_remaining(TRUE)) { $process = FEEDAPI_CRON_FEEDS; $result = db_query_range("SELECT f.nid, n.uid FROM {feedapi} f JOIN {node} n ON n.vid = f.vid WHERE next_refresh_time <= %d AND next_refresh_time <> %d ORDER BY next_refresh_time ASC", $now, FEEDAPI_CRON_NEVER_REFRESH, 0, FEEDAPI_CRON_FEEDS); - while (feedapi_cron_time() && $feed = db_fetch_object($result)) { + while (feedapi_time_remaining(TRUE) && $feed = db_fetch_object($result)) { $user = user_load(array('uid' => $feed->uid)); // Call the refresh process for each feed and store counters $counter = feedapi_invoke('refresh', $feed, TRUE); @@ -740,20 +740,27 @@ function feedapi_cron() { * @return * Number of seconds left, zero if none. */ -function feedapi_cron_time() { +function feedapi_time_remaining($is_cron = FALSE) { static $time_limit; - if (!$time_limit) { - $max_exec_time = ini_get('max_execution_time') == 0 ? 120 : ini_get('max_execution_time'); - $time_limit = time() + (variable_get('feedapi_cron_percentage', 15) / 100) * $max_exec_time; - // However, check for left time, maybe some other cron processing already occured - $cron_semaphore = variable_get('cron_semaphore', 0); - if ($cron_semaphore) { - $time_limit = min($time_limit, $cron_semaphore + $max_exec_time); + if ($is_cron) { + if (!$time_limit) { + $max_exec_time = ini_get('max_execution_time') == 0 ? 120 : ini_get('max_execution_time'); + $time_limit = time() + (variable_get('feedapi_cron_percentage', 15) / 100) * $max_exec_time; + // However, check for left time, maybe some other cron processing already occured + $cron_semaphore = variable_get('cron_semaphore', 0); + if ($cron_semaphore) { + $time_limit = min($time_limit, $cron_semaphore + $max_exec_time); + } + timer_start('feedapi_cron'); } - timer_start('feedapi_cron'); + return max($time_limit - time(), 0); + } + else { + // This refresh is not the result of a cron hook execution, but a manual refresh. + $execution_time = ini_get('max_execution_time') - 5; + return max($execution_time - round(timer_read('page') / 1000), 0); } - return max($time_limit - time(), 0); } /** @@ -1266,7 +1273,7 @@ function _feedapi_invoke_refresh(&$feed, $updated = ($item->is_updated && !$item->is_new) ? $updated + 1 : $updated; // Decision on time. If the exec time is greather than the user-set percentage of php max execution time - if ($cron && !feedapi_cron_time()) { + if (!feedapi_time_remaining($cron)) { $half_done = ($new + $updated) == count($items) ? FALSE : TRUE; break; }