Merge pull request #136 from green-ponies/master

Memory calculation adjustments
This commit is contained in:
Shish Moom 2012-02-13 02:56:54 -08:00
commit 9af3a765b4
4 changed files with 81 additions and 21 deletions

View File

@ -1,11 +1,14 @@
_________.__ .__ .__ ________
/ _____/| |__ |__| _____ _____ |__| ____ \_____ \
\_____ \ | | \| |/ \ / \| |/ __ \ / ____/
/ \| Y \ | Y Y \ Y Y \ \ ___// \
/_______ /|___| /__|__|_| /__|_| /__|\___ >_______ \
\_____ \ | | \ | | / \ / \ | |_/ __ \ / ____/
/ \| Y \| || Y Y \| Y Y \| |\ ___/ / \
/_______ /|___| /|__||__|_| /|__|_| /|__| \___ >\_______ \
\/ \/ \/ \/ \/ \/
_________________________________________________________________________
Shimmie Alpha
~~~~~~~~~~~~~
If you're reading this on github and looking for the stable version, go
@ -58,6 +61,15 @@ database and file formats haven't changed *completely*, it's different
enough to be a pain.
Custom Configuration
~~~~~~~~~~~~~~~~~~~~
Various aspects of Shimmie can be configured to suit your site specific
needs via the file "config.php" (created after installation).
Take a look at "core/default_config.inc.php" for the available options
that can used.
Development Info
~~~~~~~~~~~~~~~~
http://shimmie.shishnet.org/doc/
@ -70,7 +82,7 @@ Contact
~~~~~~~
#shimmie on Freenode -- IRC
webmaster at shishnet.org -- email
https://github.com/shish/shimmie2 -- bug tracker
https://github.com/shish/shimmie2/issues -- bug tracker
Licence

View File

@ -172,8 +172,19 @@ class ResizeImage extends Extension {
throw new ImageResizeException("The image size does not match what is in the database! - Aborting Resize.");
}
/* Check memory usage limits */
$memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
/*
Check Memory usage limits
Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
New check: memory_use = width * height * (bits per channel) * channels * 2.5
It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4)
We need to consider the size that we are GOING TO instead.
The factor of 2.5 is simply a rough guideline.
http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
*/
$memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
$memory_limit = get_memory_limit();
if ($memory_use > $memory_limit) {

View File

@ -1,4 +1,16 @@
<?php
/**
* These are the default configuration options for Shimmie.
*
* All of these can be over-ridden by placing a 'define' in config.php
*
* Do NOT change them in this file. These are the defaults only!
*
* Example:
* define("SPEED_HAX", true);
*
*/
// to change these system-level settings, do define("FOO", 123); in config.php
function _d($name, $value) {if(!defined($name)) define($name, $value);}
_d("DATABASE_DSN", null); // string PDO database connection details
@ -18,4 +30,5 @@ _d("WH_SPLITS", 1); // int how many levels of subfolders to put in
_d("VERSION", 'trunk'); // string shimmie version
_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version
_d("TIMEZONE", null); // string timezone
?>

View File

@ -547,24 +547,48 @@ function get_memory_limit() {
global $config;
// thumbnail generation requires lots of memory
$default_limit = 8*1024*1024;
$default_limit = 8*1024*1024; // 8 MB of memory is PHP's default.
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_mem_limit"));
if($shimmie_limit < 3*1024*1024) {
// we aren't going to fit, override
$shimmie_limit = $default_limit;
}
ini_set("memory_limit", $shimmie_limit);
/*
Get PHP's configured memory limit.
Note that this is set to -1 for NO memory limit.
http://ca2.php.net/manual/en/ini.core.php#ini.memory-limit
*/
$memory = parse_shorthand_int(ini_get("memory_limit"));
// changing of memory limit is disabled / failed
if ($memory == -1) {
$memory = $default_limit;
// No memory limit.
// Return the larger of the set limits.
if ($shimmie_limit > $default_limit) {
return $shimmie_limit;
} else {
return $default_limit; // return the default memory limit
}
} else {
// PHP has a memory limit set.
if ($shimmie_limit > $memory) {
// Shimmie wants more memory than what PHP is currently set for.
// Attempt to set PHP's memory limit.
if ( ini_set("memory_limit", $shimmie_limit) === FALSE ) {
/* We can't change PHP's limit, oh well, return whatever its currently set to */
return $memory;
}
$memory = parse_shorthand_int(ini_get("memory_limit"));
}
assert($memory > 0);
return $memory;
// PHP's memory limit is more than Shimmie needs.
return $memory; // return the current setting
}
}
/**