function drupal_check_memory_limit

Compares the memory required for an operation to the available memory.

Parameters

$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).

$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 value

TRUE if there is sufficient memory to allow the operation, or FALSE otherwise.

4 calls to drupal_check_memory_limit()
color_scheme_form_submit in drupal/core/modules/color/color.module
Form submission handler for color_scheme_form().
MiscUnitTest::testCheckMemoryLimit in drupal/core/modules/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php
Tests that the drupal_check_memory_limit() function works as expected.
simpletest_requirements in drupal/core/modules/simpletest/simpletest.install
Implements hook_requirements().
system_requirements in drupal/core/modules/system/system.install
Test and report Drupal installation requirements.

File

drupal/core/includes/bootstrap.inc, line 3094
Functions that need to be loaded on every Drupal request.

Code

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 or equal to the memory required for
  //   the operation.
  return !$memory_limit || $memory_limit == -1 || parse_size($memory_limit) >= parse_size($required);
}