Make WordPress Core


Ignore:
Timestamp:
09/09/2011 07:59:44 PM (13 years ago)
Author:
ryan
Message:

Improve cron locking. Avoid multiple cron processes looping over the same events. fixes #17462

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/cron.php

    r16938 r18659  
    205205    * try to make this as atomic as possible by setting doing_cron switch
    206206    */
    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;
    211211
    212212    // 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 )
    214214        return;
    215215
     
    227227            return;
    228228
    229         set_transient( 'doing_cron', $local_time );
     229        $doing_wp_cron = $local_time;
     230        set_transient( 'doing_cron', $doing_wp_cron );
    230231
    231232        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'])) );
    233234        echo ' ';
    234235
     
    241242    }
    242243
    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;
    246248    wp_remote_post( $cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true)) );
    247249}
Note: See TracChangeset for help on using the changeset viewer.