Make WordPress Core

Changeset 55871


Ignore:
Timestamp:
05/30/2023 06:46:58 PM (17 months ago)
Author:
johnbillion
Message:

Cron API: Attempt to raise the PHP memory limit for cron event processing.

Since cron events often consume extra memory by nature, it makes sense to give them the full amount available by default. In practice this means the memory will be increased to WP_MAX_MEMORY_LIMIT (which is 256MB by default) during cron event processing if the default memory limit is lower than this value.

The new cron_memory_limit filter can be used to adjust this value if necessary.

Note that this change will not by default affect external means of processing cron events, such as the wp cron command in WP-CLI, server-level crontab events, or any other cron event processing mechanism that bypasses wp-cron.php.

Props iandunn, thakkarhardik

Fixes #56628

Location:
trunk/src
Files:
2 edited

Legend:

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

    r54866 r55871  
    4646    require_once __DIR__ . '/wp-load.php';
    4747}
     48
     49// Attempt to raise the PHP memory limit for cron event processing.
     50wp_raise_memory_limit( 'cron' );
    4851
    4952/**
  • trunk/src/wp-includes/functions.php

    r55870 r55871  
    75247524 *
    75257525 * @param string $context Optional. Context in which the function is called. Accepts either 'admin',
    7526  *                        'image', or an arbitrary other context. If an arbitrary context is passed,
     7526 *                        'image', 'cron', or an arbitrary other context. If an arbitrary context is passed,
    75277527 *                        the similarly arbitrary {@see '$context_memory_limit'} filter will be
    75287528 *                        invoked. Default 'admin'.
     
    75837583             */
    75847584            $filtered_limit = apply_filters( 'image_memory_limit', $filtered_limit );
     7585            break;
     7586
     7587        case 'cron':
     7588            /**
     7589             * Filters the memory limit allocated for WP-Cron event processing.
     7590             *
     7591             * @since 6.3.0
     7592             *
     7593             * @param int|string $filtered_limit Maximum memory limit to allocate for WP-Cron.
     7594             *                                   Default `WP_MAX_MEMORY_LIMIT` or the original
     7595             *                                   php.ini `memory_limit`, whichever is higher.
     7596             *                                   Accepts an integer (bytes), or a shorthand string
     7597             *                                   notation, such as '256M'.
     7598             */
     7599            $filtered_limit = apply_filters( 'cron_memory_limit', $filtered_limit );
    75857600            break;
    75867601
Note: See TracChangeset for help on using the changeset viewer.