예제 #1
0
파일: Core.php 프로젝트: nzjoel/sapphire
/**
 * Increase the memory limit to the given level if it's currently too low.
 * Only increases up to the maximum defined in {@link set_increase_memory_limit_max()},
 * and defaults to the 'memory_limit' setting in the PHP configuration.
 * 
 * @param A memory limit string, such as "64M".  If omitted, unlimited memory will be set.
 * @return Boolean TRUE indicates a successful change, FALSE a denied change.
 */
function increase_memory_limit_to($memoryLimit = -1)
{
    $curLimit = ini_get('memory_limit');
    // Can't go higher than infinite
    if ($curLimit == -1) {
        return true;
    }
    // Check hard maximums
    $max = get_increase_memory_limit_max();
    if ($max != -1 && translate_memstring($memoryLimit) > translate_memstring($max)) {
        return false;
    }
    // Increase the memory limit if it's too low
    if ($memoryLimit == -1 || translate_memstring($memoryLimit) > translate_memstring($curLimit)) {
        ini_set('memory_limit', $memoryLimit);
    }
    return true;
}
예제 #2
0
/**
 * Increase the memory limit to the given level if it's currently too low.
 * @param A memory limit string, such as "64M".  If omitted, unlimited memory will be set.
 */
function increase_memory_limit_to($memoryLimit = -1)
{
    $curLimit = ini_get('memory_limit');
    // Can't go higher than infinite
    if ($curLimit == -1) {
        return;
    }
    // Increase the memory limit if it's too low
    if ($memoryLimit == -1 || translate_memstring($memoryLimit) > translate_memstring($curLimit)) {
        ini_set('memory_limit', $memoryLimit);
    }
}
예제 #3
0
 /**
  * Check if we've got enough memory available for resampling this image. This check is rough,
  * so it will not catch all images that are too large - it also won't work accurately on large,
  * animated GIFs as bits per pixel can't be calculated for an animated GIF with a global color
  * table.
  *
  * @param string $filename
  * @return boolean
  */
 public function checkAvailableMemory($filename)
 {
     $limit = translate_memstring(ini_get('memory_limit'));
     if ($limit < 0) {
         return true;
     }
     // memory_limit == -1
     $imageInfo = getimagesize($filename);
     // bits per channel (rounded up, default to 1)
     $bits = isset($imageInfo['bits']) ? ($imageInfo['bits'] + 7) / 8 : 1;
     // channels (default 4 rgba)
     $channels = isset($imageInfo['channels']) ? $imageInfo['channels'] : 4;
     $bytesPerPixel = $bits * $channels;
     // width * height * bytes per pixel
     $memoryRequired = $imageInfo[0] * $imageInfo[1] * $bytesPerPixel;
     return $memoryRequired + memory_get_usage() < $limit;
 }