Ticket #9005: 9005.patch
File 9005.patch, 4.5 KB (added by , 16 years ago) |
---|
-
wp-cron.php
11 11 12 12 ignore_user_abort(true); 13 13 14 /** 15 * Tell WordPress we are doing the CRON task. 16 * 17 * @var bool 18 */ 19 define('DOING_CRON', true); 20 /** Setup WordPress environment */ 21 require_once('./wp-load.php'); 14 if ( defined('ABSPATH') ) { 15 if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) 16 return; 22 17 18 /** 19 * Tell WordPress we are doing the CRON task. 20 * 21 * @var bool 22 */ 23 define('DOING_CRON', true); 24 wp_redirect(stripslashes($_SERVER['REQUEST_URI'])); 25 flush(); 26 } else { 27 define('DOING_CRON', true); 28 29 /** Setup WordPress environment */ 30 require_once('./wp-load.php'); 31 } 32 23 33 $local_time = time(); 24 34 25 $crons = _get_cron_array(); 35 if ( !isset($crons) ) { 36 if ( false === $crons = _get_cron_array() ) 37 die(); 38 } 39 26 40 $keys = array_keys( $crons ); 27 41 28 if (!is_array($crons) || $keys[0] > $local_time) { 29 update_option('doing_cron', 0); 30 return; 31 } 42 if ( isset($keys[0]) && $keys[0] > $local_time ) 43 die(); 32 44 33 45 foreach ($crons as $timestamp => $cronhooks) { 34 35 46 if ( $timestamp > $local_time ) 36 47 break; 37 48 … … 53 64 } 54 65 } 55 66 56 update_option('doing_cron', 0);57 58 67 die(); 59 60 ?> -
wp-includes/cron.php
170 170 if ( !$timer_accurate ) 171 171 return; 172 172 173 //sanity check174 $crons = _get_cron_array();175 if ( !is_array($crons) )176 return;177 178 $keys = array_keys( $crons );179 $timestamp = $keys[0];180 if ( $timestamp > $local_time )181 return;182 183 173 /* 184 174 * multiple processes on multiple web servers can run this code concurrently 185 175 * try to make this as atomic as possible by setting doing_cron switch 186 176 */ 187 177 $flag = get_option('doing_cron'); 188 178 189 // clean up potential invalid value resulted from various system chaos 190 if ( $flag != 0 ) { 191 if ( $flag > $local_time + 10*60 || $flag < $local_time - 10*60 ) { 192 update_option('doing_cron', 0); 193 $flag = 0; 194 } 195 } 179 if ( $flag > $local_time + 10*60 ) 180 $flag = 0; 196 181 197 // don't run if another process is currently running it198 if ( $flag > $local_time )182 // don't run if another process is currently running it or more than once every 60 sec. 183 if ( $flag + 60 > $local_time ) 199 184 return; 200 185 201 update_option( 'doing_cron', $local_time + 30 ); 186 //sanity check 187 $crons = _get_cron_array(); 188 if ( !is_array($crons) ) 189 return; 202 190 203 add_action('wp_head', 'spawn_cron_request'); 191 $keys = array_keys( $crons ); 192 if ( isset($keys[0]) && $keys[0] > $local_time ) 193 return; 194 195 update_option( 'doing_cron', $local_time ); 196 197 include_once(ABSPATH . 'wp-cron.php'); 204 198 } 205 199 206 200 /** … … 213 207 function wp_cron() { 214 208 215 209 // Prevent infinite loops caused by lack of wp-cron.php 216 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false )210 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) 217 211 return; 218 212 219 $crons = _get_cron_array(); 220 221 if ( !is_array($crons) ) 213 if ( false === $crons = _get_cron_array() ) 222 214 return; 223 215 216 $local_time = time(); 224 217 $keys = array_keys( $crons ); 225 if ( isset($keys[0]) && $keys[0] > time())218 if ( isset($keys[0]) && $keys[0] > $local_time ) 226 219 return; 227 220 228 $local_time = time();229 221 $schedules = wp_get_schedules(); 230 222 foreach ( $crons as $timestamp => $cronhooks ) { 231 223 if ( $timestamp > $local_time ) break; … … 370 362 return true; 371 363 } 372 364 373 function spawn_cron_request() {374 365 ?> 375 <script type="text/javascript">376 /* <![CDATA[ */377 window.setTimeout(function(){var x;if(window.XMLHttpRequest){x=new XMLHttpRequest();}else{try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}}if(x){x.open('GET','<?php echo get_option('siteurl'); ?>/wp-cron.php?'+(new Date()).getTime(), true);x.send('');}},10);378 /* ]]> */379 </script>380 <?php381 }382 383 ?> -
wp-includes/default-filters.php
176 176 add_action('wp_head', 'wp_generator'); 177 177 add_action('wp_footer', 'wp_print_footer_scripts'); 178 178 if(!defined('DOING_CRON')) 179 add_action(' init', 'wp_cron');179 add_action('sanitize_comment_cookies', 'wp_cron'); 180 180 add_action('do_feed_rdf', 'do_feed_rdf', 10, 1); 181 181 add_action('do_feed_rss', 'do_feed_rss', 10, 1); 182 182 add_action('do_feed_rss2', 'do_feed_rss2', 10, 1);