Merge pull request #136 from green-ponies/master
Memory calculation adjustments
This commit is contained in:
commit
9af3a765b4
26
README.txt
26
README.txt
@ -1,10 +1,13 @@
|
|||||||
|
|
||||||
_________.__ .__ .__ ________
|
_________.__ .__ .__ ________
|
||||||
/ _____/| |__ |__| _____ _____ |__| ____ \_____ \
|
/ _____/| |__ |__| _____ _____ |__| ____ \_____ \
|
||||||
\_____ \ | | \| |/ \ / \| |/ __ \ / ____/
|
\_____ \ | | \ | | / \ / \ | |_/ __ \ / ____/
|
||||||
/ \| Y \ | Y Y \ Y Y \ \ ___// \
|
/ \| Y \| || Y Y \| Y Y \| |\ ___/ / \
|
||||||
/_______ /|___| /__|__|_| /__|_| /__|\___ >_______ \
|
/_______ /|___| /|__||__|_| /|__|_| /|__| \___ >\_______ \
|
||||||
\/ \/ \/ \/ \/ \/
|
\/ \/ \/ \/ \/ \/
|
||||||
|
|
||||||
|
_________________________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
Shimmie Alpha
|
Shimmie Alpha
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
@ -58,6 +61,15 @@ database and file formats haven't changed *completely*, it's different
|
|||||||
enough to be a pain.
|
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
|
Development Info
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
http://shimmie.shishnet.org/doc/
|
http://shimmie.shishnet.org/doc/
|
||||||
@ -70,7 +82,7 @@ Contact
|
|||||||
~~~~~~~
|
~~~~~~~
|
||||||
#shimmie on Freenode -- IRC
|
#shimmie on Freenode -- IRC
|
||||||
webmaster at shishnet.org -- email
|
webmaster at shishnet.org -- email
|
||||||
https://github.com/shish/shimmie2 -- bug tracker
|
https://github.com/shish/shimmie2/issues -- bug tracker
|
||||||
|
|
||||||
|
|
||||||
Licence
|
Licence
|
||||||
|
@ -172,8 +172,19 @@ class ResizeImage extends Extension {
|
|||||||
throw new ImageResizeException("The image size does not match what is in the database! - Aborting Resize.");
|
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();
|
$memory_limit = get_memory_limit();
|
||||||
|
|
||||||
if ($memory_use > $memory_limit) {
|
if ($memory_use > $memory_limit) {
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
<?php
|
<?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
|
// to change these system-level settings, do define("FOO", 123); in config.php
|
||||||
function _d($name, $value) {if(!defined($name)) define($name, $value);}
|
function _d($name, $value) {if(!defined($name)) define($name, $value);}
|
||||||
_d("DATABASE_DSN", null); // string PDO database connection details
|
_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("VERSION", 'trunk'); // string shimmie version
|
||||||
_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version
|
_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version
|
||||||
_d("TIMEZONE", null); // string timezone
|
_d("TIMEZONE", null); // string timezone
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -547,24 +547,48 @@ function get_memory_limit() {
|
|||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
// thumbnail generation requires lots of memory
|
// 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"));
|
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_mem_limit"));
|
||||||
|
|
||||||
if($shimmie_limit < 3*1024*1024) {
|
if($shimmie_limit < 3*1024*1024) {
|
||||||
// we aren't going to fit, override
|
// we aren't going to fit, override
|
||||||
$shimmie_limit = $default_limit;
|
$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"));
|
$memory = parse_shorthand_int(ini_get("memory_limit"));
|
||||||
|
|
||||||
// changing of memory limit is disabled / failed
|
if ($memory == -1) {
|
||||||
if($memory == -1) {
|
// No memory limit.
|
||||||
$memory = $default_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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// PHP's memory limit is more than Shimmie needs.
|
||||||
|
return $memory; // return the current setting
|
||||||
}
|
}
|
||||||
|
|
||||||
assert($memory > 0);
|
|
||||||
|
|
||||||
return $memory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user