Changeset 10521
- Timestamp:
- 02/07/2009 01:32:34 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-cron.php
r10519 r10521 12 12 ignore_user_abort(true); 13 13 14 if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) 15 die(); 16 14 17 /** 15 18 * Tell WordPress we are doing the CRON task. … … 18 21 */ 19 22 define('DOING_CRON', true); 20 /** Setup WordPress environment */21 require_once('./wp-load.php');22 23 24 if ( !defined('ABSPATH') ) { 25 /** Setup WordPress environment */ 26 require_once('./wp-load.php'); 27 } 28 29 if ( false === $crons = _get_cron_array() ) 30 die(); 31 32 $keys = array_keys( $crons ); 23 33 $local_time = time(); 24 34 25 $crons = _get_cron_array(); 26 $keys = array_keys( $crons ); 27 28 if (!is_array($crons) || $keys[0] > $local_time) { 29 set_transient('doing_cron', 0); 30 return; 31 } 35 if ( isset($keys[0]) && $keys[0] > $local_time ) 36 die(); 32 37 33 38 foreach ($crons as $timestamp => $cronhooks) { 34 35 39 if ( $timestamp > $local_time ) 36 40 break; … … 54 58 } 55 59 56 set_transient('doing_cron', 0);57 58 60 die(); 59 60 ?> -
trunk/wp-includes/cron.php
r10519 r10521 161 161 * @return null Cron could not be spawned, because it is not needed to run. 162 162 */ 163 function spawn_cron( $local_time ) { 163 function spawn_cron( $local_time = 0 ) { 164 165 if ( !$local_time ) 166 $local_time = time(); 167 168 if ( defined('DOING_CRON') || isset($_GET['doing_wp_cron']) ) 169 return; 164 170 165 171 /* … … 171 177 return; 172 178 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 179 /* 184 180 * multiple processes on multiple web servers can run this code concurrently … … 187 183 $flag = get_transient('doing_cron'); 188 184 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 set_transient('doing_cron', 0); 193 $flag = 0; 194 } 195 } 196 197 //don't run if another process is currently running it 198 if ( $flag > $local_time ) 199 return; 200 201 set_transient( 'doing_cron', $local_time + 30 ); 202 203 add_action('wp_head', 'spawn_cron_request'); 185 if ( $flag > $local_time + 10*60 ) 186 $flag = 0; 187 188 // don't run if another process is currently running it or more than once every 60 sec. 189 if ( $flag + 60 > $local_time ) 190 return; 191 192 //sanity check 193 $crons = _get_cron_array(); 194 if ( !is_array($crons) ) 195 return; 196 197 $keys = array_keys( $crons ); 198 if ( isset($keys[0]) && $keys[0] > $local_time ) 199 return; 200 201 if ( defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON ) { 202 if ( !empty($_POST) || defined('DOING_AJAX') ) 203 return; 204 205 set_transient( 'doing_cron', $local_time ); 206 207 ob_start(); 208 wp_redirect( add_query_arg('doing_wp_cron', '', stripslashes($_SERVER['REQUEST_URI'])) ); 209 echo ' '; 210 211 // flush any buffers and send the headers 212 while ( @ob_end_flush() ); 213 flush(); 214 215 @include_once(ABSPATH . 'wp-cron.php'); 216 return; 217 } 218 219 set_transient( 'doing_cron', $local_time ); 220 221 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?doing_wp_cron'; 222 wp_remote_post( $cron_url, array('timeout' => 0.01, 'blocking' => false) ); 204 223 } 205 224 … … 214 233 215 234 // Prevent infinite loops caused by lack of wp-cron.php 216 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false ) 217 return; 218 219 $crons = _get_cron_array(); 220 221 if ( !is_array($crons) ) 222 return; 223 235 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) 236 return; 237 238 if ( false === $crons = _get_cron_array() ) 239 return; 240 241 $local_time = time(); 224 242 $keys = array_keys( $crons ); 225 if ( isset($keys[0]) && $keys[0] > time() ) 226 return; 227 228 $local_time = time(); 243 if ( isset($keys[0]) && $keys[0] > $local_time ) 244 return; 245 229 246 $schedules = wp_get_schedules(); 230 247 foreach ( $crons as $timestamp => $cronhooks ) { … … 371 388 } 372 389 373 function spawn_cron_request() {374 390 ?> 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 ?> -
trunk/wp-includes/default-filters.php
r10442 r10521 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);
Note: See TracChangeset
for help on using the changeset viewer.