summaryrefslogtreecommitdiff
path: root/inc/common.php
diff options
context:
space:
mode:
authorMichael Klier <chi@chimeric.de>2008-10-26 14:58:33 +0100
committerMichael Klier <chi@chimeric.de>2008-10-26 14:58:33 +0100
commit13c08e2f99078e29611f641340c2ef78eaf6f560 (patch)
tree6eb7f83db7773cf75924f73e418975bb9aa88adc /inc/common.php
parent26ece5a719ce2b1307a6af5bcdef8b9177e0dff7 (diff)
downloadrpg-13c08e2f99078e29611f641340c2ef78eaf6f560.tar.gz
rpg-13c08e2f99078e29611f641340c2ef78eaf6f560.tar.bz2
moved crop/resize functions out of fetch.php for reusability
darcs-hash:20081026135833-23886-a9c8e910571c6e7a4e1603a2ebd365b3ed37108a.gz
Diffstat (limited to 'inc/common.php')
-rw-r--r--inc/common.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/inc/common.php b/inc/common.php
index 9b284617b..faee93623 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1424,4 +1424,34 @@ function license_img($type){
return '';
}
+/**
+ * Checks if the given amount of memory is available
+ *
+ * If the memory_get_usage() function is not available the
+ * function just assumes $bytes of already allocated memory
+ *
+ * @param int $mem Size of memory you want to allocate in bytes
+ * @param int $used already allocated memory (see above)
+ * @author Filip Oscadal <webmaster@illusionsoftworks.cz>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function is_mem_available($mem,$bytes=1048576){
+ $limit = trim(ini_get('memory_limit'));
+ if(empty($limit)) return true; // no limit set!
+
+ // parse limit to bytes
+ $limit = php_to_byte($limit);
+
+ // get used memory if possible
+ if(function_exists('memory_get_usage')){
+ $used = memory_get_usage();
+ }
+
+ if($used+$mem > $limit){
+ return false;
+ }
+
+ return true;
+}
+
//Setup VIM: ex: et ts=2 enc=utf-8 :