Menu

#1 Memory exceeded

open
nobody
None
5
2010-07-25
2010-07-25
Mariusz Buk
No

When big images are processed memory exceeded error occurs.

What about using this solution:
[code]
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}

return $val;
}

$MB = 1048576; // number of bytes in 1M
$K64 = 65536; // number of bytes in 64K
$TWEAKFACTOR = 1.7; // Or whatever works for you
$memoryNeeded = round( ( $_SRC["width"] * $_SRC["height"]
* $temp['bits']
* $temp['channels'] / 8
+ $K64
) * $TWEAKFACTOR
);

if ($memoryNeeded + memory_get_usage(true) > return_bytes(ini_get("memory_limit")))
{
$smarty->assign("error", "too-big");
return;
}
else
{
// to avoid using last error info if the same $smarty variable is used
$smarty->assign("error", "");
}
[/code]

Regards

Mariusz Buk

Discussion


Log in to post a comment.

MongoDB Logo MongoDB