Changeset 10521 for trunk/wp-includes/cron.php
- Timestamp:
- 02/07/2009 01:32:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 ?>
Note: See TracChangeset
for help on using the changeset viewer.