public function cache_pending() { ignore_user_abort(true); # Don't stop if the user browses away. Probably not needed. ini_set('max_execution_time', 600); # Try to work for ten minutes. This is better than set_time_limit, which is just a wrapper. $actual_MET = ini_get('max_execution_time'); # In case setting the execution time is disabled on the server if (isset($actual_MET)) { $timeout = max(time() + $actual_MET - 5, 25); # Exit a few seconds before we run out of time. } else { $timeout = time() + 25; } $posts = Word_Stats_Core::get_uncached_posts_ids(); if (count($posts)) { $posts_checked = 0; foreach ($posts as $post) { if (time() > $timeout) { exit; } Word_Stats_State::set('cache_start', time()); if (!Word_Stats_Core::is_plugin_plugged('word-stats')) { exit; } $posts_checked++; if (!get_post_meta($post->ID, 'word_stats_cached', true)) { Word_Stats_Core::cache_stats($post->ID); } } } return $posts_checked; }