wp/wp-cron.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    16  * @package WordPress
    16  * @package WordPress
    17  */
    17  */
    18 
    18 
    19 ignore_user_abort( true );
    19 ignore_user_abort( true );
    20 
    20 
    21 /* Don't make the request block till we finish, if possible. */
    21 if ( ! headers_sent() ) {
    22 if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
    22 	header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
    23 	if ( ! headers_sent() ) {
    23 	header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    24 		header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
    24 }
    25 		header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    25 
    26 	}
    26 // Don't run cron until the request finishes, if possible.
    27 
    27 if ( PHP_VERSION_ID >= 70016 && function_exists( 'fastcgi_finish_request' ) ) {
    28 	fastcgi_finish_request();
    28 	fastcgi_finish_request();
       
    29 } elseif ( function_exists( 'litespeed_finish_request' ) ) {
       
    30 	litespeed_finish_request();
    29 }
    31 }
    30 
    32 
    31 if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) {
    33 if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) {
    32 	die();
    34 	die();
    33 }
    35 }
    34 
    36 
    35 /**
    37 /**
    36  * Tell WordPress we are doing the cron task.
    38  * Tell WordPress the cron task is running.
    37  *
    39  *
    38  * @var bool
    40  * @var bool
    39  */
    41  */
    40 define( 'DOING_CRON', true );
    42 define( 'DOING_CRON', true );
    41 
    43 
    42 if ( ! defined( 'ABSPATH' ) ) {
    44 if ( ! defined( 'ABSPATH' ) ) {
    43 	/** Set up WordPress environment */
    45 	/** Set up WordPress environment */
    44 	require_once __DIR__ . '/wp-load.php';
    46 	require_once __DIR__ . '/wp-load.php';
    45 }
    47 }
       
    48 
       
    49 // Attempt to raise the PHP memory limit for cron event processing.
       
    50 wp_raise_memory_limit( 'cron' );
    46 
    51 
    47 /**
    52 /**
    48  * Retrieves the cron lock.
    53  * Retrieves the cron lock.
    49  *
    54  *
    50  * Returns the uncached `doing_cron` transient.
    55  * Returns the uncached `doing_cron` transient.
   119 		foreach ( $keys as $k => $v ) {
   124 		foreach ( $keys as $k => $v ) {
   120 
   125 
   121 			$schedule = $v['schedule'];
   126 			$schedule = $v['schedule'];
   122 
   127 
   123 			if ( $schedule ) {
   128 			if ( $schedule ) {
   124 				wp_reschedule_event( $timestamp, $schedule, $hook, $v['args'] );
   129 				$result = wp_reschedule_event( $timestamp, $schedule, $hook, $v['args'], true );
       
   130 
       
   131 				if ( is_wp_error( $result ) ) {
       
   132 					error_log(
       
   133 						sprintf(
       
   134 							/* translators: 1: Hook name, 2: Error code, 3: Error message, 4: Event data. */
       
   135 							__( 'Cron reschedule event error for hook: %1$s, Error code: %2$s, Error message: %3$s, Data: %4$s' ),
       
   136 							$hook,
       
   137 							$result->get_error_code(),
       
   138 							$result->get_error_message(),
       
   139 							wp_json_encode( $v )
       
   140 						)
       
   141 					);
       
   142 
       
   143 					/**
       
   144 					 * Fires when an error happens rescheduling a cron event.
       
   145 					 *
       
   146 					 * @since 6.1.0
       
   147 					 *
       
   148 					 * @param WP_Error $result The WP_Error object.
       
   149 					 * @param string   $hook   Action hook to execute when the event is run.
       
   150 					 * @param array    $v      Event data.
       
   151 					 */
       
   152 					do_action( 'cron_reschedule_event_error', $result, $hook, $v );
       
   153 				}
   125 			}
   154 			}
   126 
   155 
   127 			wp_unschedule_event( $timestamp, $hook, $v['args'] );
   156 			$result = wp_unschedule_event( $timestamp, $hook, $v['args'], true );
       
   157 
       
   158 			if ( is_wp_error( $result ) ) {
       
   159 				error_log(
       
   160 					sprintf(
       
   161 						/* translators: 1: Hook name, 2: Error code, 3: Error message, 4: Event data. */
       
   162 						__( 'Cron unschedule event error for hook: %1$s, Error code: %2$s, Error message: %3$s, Data: %4$s' ),
       
   163 						$hook,
       
   164 						$result->get_error_code(),
       
   165 						$result->get_error_message(),
       
   166 						wp_json_encode( $v )
       
   167 					)
       
   168 				);
       
   169 
       
   170 				/**
       
   171 				 * Fires when an error happens unscheduling a cron event.
       
   172 				 *
       
   173 				 * @since 6.1.0
       
   174 				 *
       
   175 				 * @param WP_Error $result The WP_Error object.
       
   176 				 * @param string   $hook   Action hook to execute when the event is run.
       
   177 				 * @param array    $v      Event data.
       
   178 				 */
       
   179 				do_action( 'cron_unschedule_event_error', $result, $hook, $v );
       
   180 			}
   128 
   181 
   129 			/**
   182 			/**
   130 			 * Fires scheduled events.
   183 			 * Fires scheduled events.
   131 			 *
   184 			 *
   132 			 * @ignore
   185 			 * @ignore