46 |
46 |
47 if ( false === $crons = _get_cron_array() ) |
47 if ( false === $crons = _get_cron_array() ) |
48 die(); |
48 die(); |
49 |
49 |
50 $keys = array_keys( $crons ); |
50 $keys = array_keys( $crons ); |
51 $local_time = microtime( true ); |
51 $gmt_time = microtime( true ); |
52 |
52 |
53 if ( isset($keys[0]) && $keys[0] > $local_time ) |
53 if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
54 die(); |
54 die(); |
55 |
55 |
56 $doing_cron_transient = get_transient( 'doing_cron'); |
56 $doing_cron_transient = get_transient( 'doing_cron'); |
57 |
57 |
58 // Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock. |
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 ) ) { |
59 if ( empty( $doing_wp_cron ) ) { |
60 if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { |
60 if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { |
61 // Called from external script/job. Try setting a lock. |
61 // Called from external script/job. Try setting a lock. |
62 if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $local_time ) ) |
62 if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) |
63 return; |
63 return; |
64 $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); |
64 $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); |
65 set_transient( 'doing_cron', $doing_wp_cron ); |
65 set_transient( 'doing_cron', $doing_wp_cron ); |
66 } else { |
66 } else { |
67 $doing_wp_cron = $_GET[ 'doing_wp_cron' ]; |
67 $doing_wp_cron = $_GET[ 'doing_wp_cron' ]; |
71 // Check lock |
71 // Check lock |
72 if ( $doing_cron_transient != $doing_wp_cron ) |
72 if ( $doing_cron_transient != $doing_wp_cron ) |
73 return; |
73 return; |
74 |
74 |
75 foreach ( $crons as $timestamp => $cronhooks ) { |
75 foreach ( $crons as $timestamp => $cronhooks ) { |
76 if ( $timestamp > $local_time ) |
76 if ( $timestamp > $gmt_time ) |
77 break; |
77 break; |
78 |
78 |
79 foreach ( $cronhooks as $hook => $keys ) { |
79 foreach ( $cronhooks as $hook => $keys ) { |
80 |
80 |
81 foreach ( $keys as $k => $v ) { |
81 foreach ( $keys as $k => $v ) { |