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.

git-svn-id: https://develop.svn.wordpress.org/trunk@38015 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling
2016-07-08 14:36:37 +00:00
parent ec1f83f770
commit c68f1ec772
11 changed files with 227 additions and 61 deletions
+16 -2
View File
@@ -478,12 +478,12 @@ class Tests_Functions extends WP_UnitTestCase {
'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25',
true,
),
// Android 2.2, Android Webkit Browser
// Android 2.2, Android Webkit Browser
array(
'Mozilla/5.0 (Android 2.2; Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4',
true,
),
// BlackBerry 9900, BlackBerry browser
// BlackBerry 9900, BlackBerry browser
array(
'Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+',
true,
@@ -865,4 +865,18 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertNull( wp_ext2type( 'unknown_format' ) );
}
/**
* Tests raising the memory limit.
*
* Unfortunately as the default for 'WP_MAX_MEMORY_LIMIT' in the
* test suite is -1, we can not test the memory limit negotiations.
*
* @ticket 32075
*/
function test_wp_raise_memory_limit() {
ini_set( 'memory_limit', '40M' );
$this->assertSame( -1, wp_raise_memory_limit() );
$this->assertEquals( '-1', ini_get( 'memory_limit' ) );
}
}