Changeset 18659
- Timestamp:
- 09/09/2011 07:59:44 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-cron.php
r13725 r18659 27 27 } 28 28 29 // Uncached doing_cron transient fetch 30 function _get_cron_lock() { 31 global $_wp_using_ext_object_cache, $wpdb; 32 33 $value = 0; 34 if ( $_wp_using_ext_object_cache ) { 35 // Skip local cache and force refetch of doing_cron transient in case 36 // another processs updated the cache 37 $value = wp_cache_get( 'doing_cron', 'transient', true ); 38 } else { 39 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); 40 if ( is_object( $row ) ) 41 $value = $row->option_value; 42 } 43 44 return $value; 45 } 46 29 47 if ( false === $crons = _get_cron_array() ) 30 48 die(); … … 36 54 die(); 37 55 38 foreach ($crons as $timestamp => $cronhooks) { 56 $doing_cron_transient = get_transient( 'doing_cron'); 57 58 // Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock. 59 if ( empty( $doing_wp_cron ) ) { 60 if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { 61 // Called from external script/job. Try setting a lock. 62 if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $local_time ) ) 63 return; 64 $doing_cron_transient = $doing_wp_cron = time(); 65 set_transient( 'doing_cron', $doing_wp_cron ); 66 } else { 67 $doing_wp_cron = $_GET[ 'doing_wp_cron' ]; 68 } 69 } 70 71 // Check lock 72 if ( $doing_cron_transient != $doing_wp_cron ) 73 return; 74 75 foreach ( $crons as $timestamp => $cronhooks ) { 39 76 if ( $timestamp > $local_time ) 40 77 break; 41 78 42 foreach ( $cronhooks as $hook => $keys) {79 foreach ( $cronhooks as $hook => $keys ) { 43 80 44 foreach ( $keys as $k => $v) {81 foreach ( $keys as $k => $v ) { 45 82 46 83 $schedule = $v['schedule']; 47 84 48 if ( $schedule != false) {85 if ( $schedule != false ) { 49 86 $new_args = array($timestamp, $schedule, $hook, $v['args']); 50 87 call_user_func_array('wp_reschedule_event', $new_args); 51 88 } 52 89 53 wp_unschedule_event( $timestamp, $hook, $v['args']);90 wp_unschedule_event( $timestamp, $hook, $v['args'] ); 54 91 55 do_action_ref_array($hook, $v['args']); 92 do_action_ref_array( $hook, $v['args'] ); 93 94 // If the hook ran too long and another cron process stole the lock, quit. 95 if ( _get_cron_lock() != $doing_wp_cron ) 96 return; 56 97 } 57 98 } 58 99 } 59 100 101 if ( _get_cron_lock() == $doing_wp_cron ) 102 delete_transient( 'doing_cron' ); 103 60 104 die(); -
trunk/wp-includes/cache.php
r18653 r18659 103 103 * @param int|string $key What the contents in the cache are called 104 104 * @param string $group Where the cache contents are grouped 105 * @param bool $force Whether to force an update of the local cache from the persistent cache (default is false) 105 106 * @return bool|mixed False on failure to retrieve contents or the cache 106 107 * contents on success 107 108 */ 108 function wp_cache_get( $key, $group = '') {109 global $wp_object_cache; 110 111 return $wp_object_cache->get( $key, $group);109 function wp_cache_get( $key, $group = '', $force = false ) { 110 global $wp_object_cache; 111 112 return $wp_object_cache->get( $key, $group, $force ); 112 113 } 113 114 … … 404 405 * @param int|string $key What the contents in the cache are called 405 406 * @param string $group Where the cache contents are grouped 407 * @param string $force Whether to force a refetch rather than relying on the local cache (default is false) 406 408 * @return bool|mixed False on failure to retrieve contents or the cache 407 409 * contents on success 408 410 */ 409 function get( $key, $group = 'default') {411 function get( $key, $group = 'default', $force = false) { 410 412 if ( empty ($group) ) 411 413 $group = 'default'; -
trunk/wp-includes/cron.php
r16938 r18659 205 205 * try to make this as atomic as possible by setting doing_cron switch 206 206 */ 207 $ flag= get_transient('doing_cron');208 209 if ( $ flag> $local_time + 10*60 )210 $ flag= 0;207 $lock = get_transient('doing_cron'); 208 209 if ( $lock > $local_time + 10*60 ) 210 $lock = 0; 211 211 212 212 // don't run if another process is currently running it or more than once every 60 sec. 213 if ( $ flag + 60> $local_time )213 if ( $lock + WP_CRON_LOCK_TIMEOUT > $local_time ) 214 214 return; 215 215 … … 227 227 return; 228 228 229 set_transient( 'doing_cron', $local_time ); 229 $doing_wp_cron = $local_time; 230 set_transient( 'doing_cron', $doing_wp_cron ); 230 231 231 232 ob_start(); 232 wp_redirect( add_query_arg('doing_wp_cron', '', stripslashes($_SERVER['REQUEST_URI'])) );233 wp_redirect( add_query_arg('doing_wp_cron', $doing_wp_cron, stripslashes($_SERVER['REQUEST_URI'])) ); 233 234 echo ' '; 234 235 … … 241 242 } 242 243 243 set_transient( 'doing_cron', $local_time ); 244 245 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?doing_wp_cron'; 244 $doing_wp_cron = $local_time; 245 set_transient( 'doing_cron', $doing_wp_cron ); 246 247 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?doing_wp_cron=' . $doing_wp_cron; 246 248 wp_remote_post( $cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true)) ); 247 249 } -
trunk/wp-includes/default-constants.php
r18545 r18659 269 269 if ( !defined('WP_POST_REVISIONS') ) 270 270 define('WP_POST_REVISIONS', true); 271 272 /** 273 * @since 3.3.0 274 */ 275 if ( !defined( 'WP_CRON_LOCK_TIMEOUT' ) ) 276 define('WP_CRON_LOCK_TIMEOUT', 60); // In seconds 271 277 } 272 278
Note: See TracChangeset
for help on using the changeset viewer.