WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/08/2016 02:36:37 PM (4 years ago)
Author:
ocean90
Message:

Bootstrap: Enhance core's memory limit handling.

  • Don't lower memory limit if the current limit is greater than WP_MAX_MEMORY_LIMIT.
  • Set WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT to current limit if the memory_limit setting can't be changed at runtime.
  • Use wp_convert_hr_to_bytes() when parsing the value of the memory_limit setting because it can be a shorthand or an integer value.
  • Introduce wp_raise_memory_limit( $context ) to raise the PHP memory limit for memory intensive processes. This DRYs up some logic and includes the existing admin_memory_limit and image_memory_limit filters. The function can also be used for custom contexts, the {$context}_memory_limit filter allows to customize the limit.
  • Introduce wp_is_ini_value_changeable( $setting ) to determine whether a PHP ini value is changeable at runtime.
  • Remove a function_exists( 'memory_get_usage' ) check. Since PHP 5.2.1 support for memory limit is always enabled.

Related commits: [38011-38013]

Props jrf, A5hleyRich, swissspidy, ocean90.
Fixes #32075.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-gd.php

    r37592 r38015  
    9797            return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file );
    9898
    99         /**
    100          * Filters the memory limit allocated for image manipulation.
    101          *
    102          * @since 3.5.0
    103          *
    104          * @param int|string $limit Maximum memory limit to allocate for images. Default WP_MAX_MEMORY_LIMIT.
    105          *                          Accepts an integer (bytes), or a shorthand string notation, such as '256M'.
    106          */
    107         $image_memory_limit = apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT );
    108 
    10999        // Set artificially high because GD uses uncompressed images in memory.
    110         @ini_set( 'memory_limit', $image_memory_limit );
     100        wp_raise_memory_limit( 'image' );
    111101
    112102        $this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
Note: See TracChangeset for help on using the changeset viewer.