Changeset 8927 for trunk/wp-includes/cron.php
- Timestamp:
- 09/18/2008 07:09:38 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cron.php
r8806 r8927 153 153 * @return null Cron could not be spawned, because it is not needed to run. 154 154 */ 155 function spawn_cron() { 156 $crons = _get_cron_array(); 157 155 function spawn_cron( $local_time ) { 156 global $current_blog; 157 158 /* 159 * do not even start the cron if local server timer has drifted 160 * such as due to power failure, or misconfiguration 161 */ 162 $timer_accurate = check_server_timer( $local_time ); 163 if ( !$timer_accurate ) 164 return; 165 166 //sanity check 167 $crons = _get_cron_array(); 158 168 if ( !is_array($crons) ) 159 169 return; 160 170 161 171 $keys = array_keys( $crons ); 162 if ( array_shift( $keys ) > time() ) 172 $timestamp = $keys[0]; 173 if ( $timestamp > $local_time ) 163 174 return; 164 175 165 176 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425'); 177 /* 178 * multiple processes on multiple web servers can run this code concurrently 179 * try to make this as atomic as possible by setting doing_cron switch 180 */ 181 $flag = get_option('doing_cron'); 182 183 // clean up potential invalid value resulted from various system chaos 184 if ( $flag != 0 ) { 185 if ( $flag > $local_time + 10*60 || $flag < $local_time - 10*60 ) { 186 update_option('doing_cron', 0); 187 $flag = 0; 188 } 189 } 190 191 //don't run if another process is currently running it 192 if ( $flag > $local_time ) 193 return; 194 195 update_option( 'doing_cron', $local_time + 30 ); 166 196 167 197 wp_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false)); … … 176 206 */ 177 207 function wp_cron() { 208 178 209 // Prevent infinite loops caused by lack of wp-cron.php 179 210 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false ) … … 189 220 return; 190 221 222 $local_time = time(); 191 223 $schedules = wp_get_schedules(); 192 224 foreach ( $crons as $timestamp => $cronhooks ) { 193 if ( $timestamp > time()) break;225 if ( $timestamp > $local_time ) break; 194 226 foreach ( (array) $cronhooks as $hook => $args ) { 195 227 if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) ) 196 228 continue; 197 spawn_cron( );229 spawn_cron( $local_time ); 198 230 break 2; 199 231 } … … 328 360 } 329 361 362 // stub for checking server timer accuracy, using outside standard time sources 363 function check_server_timer( $local_time ) { 364 return true; 365 } 366 330 367 ?>
Note: See TracChangeset
for help on using the changeset viewer.