diff --git a/src/wp-cron.php b/src/wp-cron.php index 417dcce375849..d068f7ab391a8 100644 --- a/src/wp-cron.php +++ b/src/wp-cron.php @@ -16,18 +16,22 @@ * @package WordPress */ -ignore_user_abort( true ); - if ( ! headers_sent() ) { header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' ); header( 'Cache-Control: no-cache, must-revalidate, max-age=0' ); } +if ( defined( 'WP_CRON_IGNORE_ABORT' ) && true === WP_CRON_IGNORE_ABORT ) { + ignore_user_abort( true ); +} + // Don't run cron until the request finishes, if possible. -if ( function_exists( 'fastcgi_finish_request' ) ) { - fastcgi_finish_request(); -} elseif ( function_exists( 'litespeed_finish_request' ) ) { - litespeed_finish_request(); +if ( defined( 'WP_CRON_FLUSH' ) && true === WP_CRON_FLUSH ) { + if ( function_exists( 'fastcgi_finish_request' ) ) { + fastcgi_finish_request(); + } elseif ( function_exists( 'litespeed_finish_request' ) ) { + litespeed_finish_request(); + } } if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) { diff --git a/src/wp-includes/default-constants.php b/src/wp-includes/default-constants.php index acfc878fb7138..ebad0cf4d01ef 100644 --- a/src/wp-includes/default-constants.php +++ b/src/wp-includes/default-constants.php @@ -398,6 +398,30 @@ function wp_functionality_constants() { if ( ! defined( 'WP_CRON_LOCK_TIMEOUT' ) ) { define( 'WP_CRON_LOCK_TIMEOUT', MINUTE_IN_SECONDS ); } + + /** + * Wether or not to ignore user abort when running wp-cron + * + * @see https://www.php.net/manual/en/function.ignore-user-abort.php + */ + if ( ! defined( 'WP_CRON_IGNORE_ABORT' ) ) { + define( 'WP_CRON_IGNORE_ABORT', true ); + } + + /** + * Flush wp-cron response data + * + * Wether or not to flush wp-cron response data and close the HTTP request + * before continuing in the background. This invokes a child process in + * PHP-FPM and LSPHP and closes the HTTP connection to the client. + * + * @link https://www.php.net/manual/en/function.ignore-user-abort.php + * @link https://www.php.net/manual/en/function.fastcgi-finish-request.php + * @link https://www.php.net/manual/en/function.litespeed-finish-request.php + */ + if ( ! defined( 'WP_CRON_FLUSH' ) ) { + define( 'WP_CRON_FLUSH', true ); + } } /**