diff options
author | David Rothstein <drothstein@gmail.com> | 2013-08-05 23:58:15 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-08-05 23:58:15 -0400 |
commit | 19e65b966c79e7061827ef5f21ac67cd1159806c (patch) | |
tree | f5715889843ee7c991ff70083f31b2a55a0a2656 /includes | |
parent | ebe236b0c03750c624cd00db96fc535077e6f890 (diff) | |
download | brdo-19e65b966c79e7061827ef5f21ac67cd1159806c.tar.gz brdo-19e65b966c79e7061827ef5f21ac67cd1159806c.tar.bz2 |
Issue #1453984 by xjm, naxoc, Dave Reid, underq, dags, tim.plunkett, Heine: Fixed Color module doesn't test for unlimited memory.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index eddee8886..7f4033dfb 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -3414,3 +3414,32 @@ function _drupal_shutdown_function() { } } } + +/** + * Compares the memory required for an operation to the available memory. + * + * @param $required + * The memory required for the operation, expressed as a number of bytes with + * optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes, + * 9mbytes). + * @param $memory_limit + * (optional) The memory limit for the operation, expressed as a number of + * bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, + * 6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP + * memory_limit will be used. Defaults to NULL. + * + * @return + * TRUE if there is sufficient memory to allow the operation, or FALSE + * otherwise. + */ +function drupal_check_memory_limit($required, $memory_limit = NULL) { + if (!isset($memory_limit)) { + $memory_limit = ini_get('memory_limit'); + } + + // There is sufficient memory if: + // - No memory limit is set. + // - The memory limit is set to unlimited (-1). + // - The memory limit is greater than the memory required for the operation. + return ((!$memory_limit) || ($memory_limit == -1) || (parse_size($memory_limit) >= parse_size($required))); +} |