WordPress.org

Make WordPress Core

Ticket #3141: 3141.r6668.diff

File 3141.r6668.diff, 4.1 KB (added by darkdragon, 10 years ago)

updated patch which moves a function to pluggable, so that plugins can replace the functionality in the function. Based on r6668

  • wp-includes/functions.php

     
    16761676                        trigger_error( printf( __("%s is <strong>deprecated</strong> since version %s with no alternative available."), $file, $version ) );
    16771677        }
    16781678}
     1679
     1680/**
     1681 * _set_memory_limit() - Try to set PHP memory limit to amount
     1682 *
     1683 * If the amount is not given, then the default is to set the amount
     1684 * to '32MB', however the parameter available will allow setting the
     1685 * amount to something other than '32MB'.
     1686 *
     1687 * Failure might mean that the memory limit is already higher than
     1688 * either the default or the amount given. It could mean that ini_set
     1689 * and/or ini_get has been disabled and either getting and/or setting
     1690 * could not be accomplished.
     1691 *
     1692 * @since 2.5
     1693 * @access private
     1694 *
     1695 * @param string $mib MiB amount as a string with MiB amount followed by 'M'. Default is 32M.
     1696 * @return bool True if the amount was set by this function or already 32MB, false on failure.
     1697 */
     1698function _set_memory_limit($mib='32M') {
     1699        if( !function_exists('memory_get_usage') )
     1700                return null;
     1701
     1702        if( (int) @ini_get('memory_limit') < absint($mib) )
     1703                @ini_set('memory_limit', $mib);
     1704
     1705        if( @ini_get('memory_limit') == $mib )
     1706                return true;
     1707
     1708        return false;
     1709}
     1710
     1711/**
     1712 * wp_get_memory_limit() - Return the PHP memory limit in MiB
     1713 *
     1714 * If null is returned, then --enable-memory-limit directive was
     1715 * not enabled during PHP install (< 5.2.1). Prior to PHP 5.2.1
     1716 * if --enable-memory-limit was not used during the install of
     1717 * PHP, then memory_get_usage() would not exist in PHP.
     1718 *
     1719 * So Failure (false return value) might also mean that
     1720 * memory_limit is unavailable on PHP version greater than PHP
     1721 * 5.2.1.
     1722 *
     1723 * @todo Complete edge cases which have the memory limit set to something
     1724 *              other than 'M'. The Memory limit can be an integer
     1725 *
     1726 * @since 2.5
     1727 *
     1728 * @return bool|int False if memory limit is not already in MiB or the MiB amount
     1729 */
     1730function wp_get_memory_limit() {
     1731        if( !function_exists('memory_get_usage') )
     1732                return null;
     1733
     1734        $iMemoryLimit = @ini_get('memory_limit');
     1735
     1736        if( false !== stripos($iMemoryLimit, 'm') )
     1737                return absint($iMemoryLimit);
     1738       
     1739        return false;
     1740}
     1741
    16791742?>
  • wp-includes/pluggable.php

     
    12601260}
    12611261endif;
    12621262
     1263if ( !function_exists('wp_increase_memory_limit') ) :
     1264/**
     1265 * wp_increase_memory_limit() - Increase PHP memory limit when needed
     1266 *
     1267 * This function can be applied to memory intensive loops to slowly increase
     1268 * the memory when needed instead of just failing.
     1269 *
     1270 * Null return value means that the function to get the current memory
     1271 * usage is unavailable. False return value can mean that the increase is
     1272 * not needed at the moment or that the memory limit could not be increased.
     1273 *
     1274 * @todo Return WP_Error instead of false or instead apply this todo to
     1275 *              the wp_set_memory_limit() function instead to return a WP_Error.
     1276 * @since 2.5
     1277 *
     1278 * @return null|bool True on success. Null if can't increase memory
     1279 */
     1280function wp_increase_memory_limit() {
     1281        if( !function_exists('memory_get_usage') )
     1282                return null;
     1283
     1284        $iMemoryLimit = (int) @ini_get('memory_limit');
     1285        $iWhenIncrease = (int) $iMemoryLimit * 0.75;
     1286
     1287        $iCurrentUsage = memory_get_usage() / 1048576; // Divide by Megabytes
     1288
     1289        if( $iCurrentUsage >= $iWhenIncrease ) {
     1290                $iIncreaseToAmount = ($iMemoryLimit+$iWhenIncrease).'MB';
     1291                return _set_memory_limit( $iIncreaseToAmount );
     1292        }
     1293
     1294        return false;
     1295}
     1296endif;
     1297
    12631298?>
  • wp-settings.php

     
    194194require (ABSPATH . WPINC . '/functions.php');
    195195require (ABSPATH . WPINC . '/classes.php');
    196196
     197if( defined('WP_MEMORY_LIMIT') )
     198        _set_memory_limit( WP_MEMORY_LIMIT );
     199else
     200        _set_memory_limit();
     201
    197202require_wp_db();
    198203
    199204if ( !empty($wpdb->error) )