/** * Shutdown function for detecting if the PHP script reaches the maximum execution time limit * while importing a feed. * * @since 4.6.6 */ function wprss_detect_exec_timeout() { // Get last error if ($error = error_get_last()) { // Check if it is an E_ERROR and if it is a max exec time limit error if ($error['type'] === E_ERROR && stripos($error['message'], 'maximum execution') === 0) { // If the importing process was running if (array_key_exists('wprss_importing_feed', $GLOBALS) && $GLOBALS['wprss_importing_feed'] !== NULL) { // Get the ID of the feed that was importing $feed_ID = $GLOBALS['wprss_importing_feed']; // Perform clean up wprss_flag_feed_as_idle($feed_ID); $msg = sprintf(__('The PHP script timed out while importing an item from this feed, after %d seconds.', WPRSS_TEXT_DOMAIN), wprss_get_item_import_time_limit()); update_post_meta($feed_ID, 'wprss_error_last_import', $msg); // Log the error wprss_log('The PHP script timed out while importing feed #' . $feed_ID, NULL, WPRSS_LOG_LEVEL_ERROR); } } } }
/** * Returns whether or not the feed source is updating. * * @param (string|int) The id of the feed source * @return (bool) TRUE if the feed source is currently updating, FALSE otherwise. * */ function wprss_is_feed_source_updating($id) { // Get the 'updating' meta field $is_updating_meta = get_post_meta($id, 'wprss_feed_is_updating', TRUE); // Check if the feed has the 'updating' meta field set if ($is_updating_meta === '') { // If not, then the feed is not updating return FALSE; } // Get the limit used for the feed $limit = get_post_meta($id, 'wprss_limit', true); if ($limit === '' || intval($limit) <= 0) { $global_limit = wprss_get_general_setting('limit_feed_items_imported'); $limit = $global_limit === '' || intval($global_limit) <= 0 ? NULL : $global_limit; } // Calculate the allowed maximum time, based on the maximum number of items allowed to be // imported from this source. // If no limit is used, 60s (1min) is used. $single_item_time_limit = wprss_get_item_import_time_limit(); $allowed_time = $limit === NULL ? 60 : $single_item_time_limit * intval($limit); // Calculate how many seconds have passed since the feed last signalled that it is updating $diff = time() - $is_updating_meta; // If the difference is greater than the allowed maximum amount of time, mark the feed as idle. if ($diff > $allowed_time) { wprss_flag_feed_as_idle($id); // Feed is not updating return FALSE; } // Feed is updating return TRUE; }