Php photo gallery TWG | JFUploader | TWG Flash upload | WFU | Forum

Get help for TinyWebGallery, the best image gallery. The forum is also home for the Joomla JFUploader, TWG Flash Uploader and the Wordpress flash uploader.
It is currently 25. Apr 2024, 23:44

This forum is readonly now. Please use the new forum if you don't find the answer to your question here. The new forum is at https://www.tinywebgallery.com/blog/forum/


All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 22. Sep 2009, 13:53 
Offline

Joined: 5. Jul 2009, 11:25
Posts: 8
I am using JFU on a server with PHP memory limit set to 16MB. JFU falls over trying to resize any pic 2000 + pixels.

Why not increase the memory limit for this script?

A possible tweek of tfu_helper.php to do this:
Code:
function isMemoryOk($oldsize, $image_name, $debug = true)
{
    // if (isset($oldsize) && ($oldsize[0] == 0)) { // we cannot read the size - therefore we assume it's enough memory available.
    // return true;
    // }
    $memory = ($oldsize[0] * $oldsize[1] * 6) + 1048576; // mem and we add 1 MB for safty

/* jb increase memory as needed */
$InUse=memory_get_usage();
//debug('Before Memory in use ' . $InUse . ' Needed ' . $memory . ' Limit ' . ini_get('memory_limit'));
if ($memory > return_kbytes(ini_get('memory_limit')) - $InUse)
{
   //Try to set it
   ini_set('memory_limit',$memory + $InUse);
}
//debug('After  Memory in use ' . $InUse . ' Needed ' . $memory . ' Limit ' . ini_get('memory_limit'));

    $memory_limit = return_kbytes(ini_get('memory_limit')) * 1024;
    if ($memory > $memory_limit && $memory_limit > 0) { // we store the number of images that have a size problem in the session and output this in the readDir file
        $mem_errors = 0;
        if (isset($_SESSION['upload_memory_limit'])) {
            $mem_errors = $_SESSION['upload_memory_limit'];
        }
        $_SESSION['upload_memory_limit'] = ($mem_errors + 1);
        if ($debug) {
            debug('File ' . $image_name . ' cannot be processed because not enough memory is available! Needed: ~' . $memory . '. Available: ' . $memory_limit);
        }
        return false;
    } else {
        return true;
    }
}


Last edited by jbudd on 22. Sep 2009, 13:59, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 13:57 
Offline

Joined: 5. Jul 2009, 11:25
Posts: 8
Of course the Info/Limits/Register would have to be changed too, maybe "The script will attempt to get around limitations due to the PHP memory limit"


Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 14:01 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
Most of the server do not allow to increase the memory limit with php.
Does yours?

- Michael


Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 17:11 
Offline

Joined: 5. Jul 2009, 11:25
Posts: 8
I believe that PHP has to be compiled with a particular option to allow this. ini_set ("memory_limit"... ); appears in the component Extplorer and the plugin Content Optimizer, which work on my site, so it should work in JFU


Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 17:15 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
In TWG I have a special parameter where you can enable the increase. I check if I can do this automatically - because setting the value and that it is used are 2 different things. And if I cannot detect this then I cannot provide a good error message for the user ...

-Michael


Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 17:41 
Offline

Joined: 5. Jul 2009, 11:25
Posts: 8
I'm not clear what you mean Michael.

With the above code, if PHP is set up to deny ini_set() requests, the user should get the same "n images could not be resized because of insufficient memory" that they get now?

jb


Top
 Profile  
 
 Post subject:
PostPosted: 22. Sep 2009, 18:12 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
this was my point - how does it deny it?
or can i set it - I do get the new value back and it just ignores it?

- Michael


Top
 Profile  
 
 Post subject:
PostPosted: 23. Sep 2009, 11:03 
Offline

Joined: 5. Jul 2009, 11:25
Posts: 8
I tried it on my PC with wampserver (slightly different code - below)

The only way I could get ini_set() to fail was by using safe_mode = On in php.ini.

The user gets the message 2 file(s) of 2 could not be uploaded. For 2 file(s) the server had not enough memory to resize!
There is nothing in the PHP error log.
tfu.log contains
Code:
09.23.2009 10:53:16 - Trying to resize DSCF1785.JPG 3488x2616 Before: Memory needed 55796224 + 1223152 (in use) = 57019376 Limit:16M
09.23.2009 10:53:16 - After: Limit 16M
09.23.2009 10:53:16 - File DSCF1785.JPG cannot be processed because not enough memory is available! Needed: ~55796224. Available: 16777216
09.23.2009 10:53:17 - Trying to resize ox 109.JPG 2816x2112 Before: Memory needed 36732928 + 1223144 (in use) = 37956072 Limit:16M
09.23.2009 10:53:17 - After: Limit 16M
09.23.2009 10:53:17 - File ox 109.JPG cannot be processed because not enough memory is available! Needed: ~36732928. Available: 16777216


With safe_mode = Off the pictures are resized successfully.
tfu.log has
Code:
09.23.2009 10:49:32 - Trying to resize DSCF1074.JPG 3488x2616 Before: Memory needed 55796224 + 1223152 (in use) = 57019376 Limit:16M
09.23.2009 10:49:32 - After: Limit 57019376
09.23.2009 10:49:42 - Trying to resize ox 109.JPG 2816x2112 Before: Memory needed 36732928 + 1223272 (in use) = 37956200 Limit:16M
09.23.2009 10:49:42 - After: Limit 37956200


I notice that the memory limit reverts to 16M after the first file is processed.

Conclusion: If ini_set() fails, the program seems to operate as standard. If ini_set() works, it can resize bigger pictures. It seems to be a useful mod.

This is the corrected code I used
Code:
/* jb increase memory as needed */
$InUse=memory_get_usage();
// Check if we need to set it
if ($memory > return_kbytes(ini_get('memory_limit'))*1024 - $InUse)
{
debug('Trying to resize ' . $image_name . ' ' . $oldsize[0] . 'x' . $oldsize[1] . ' Before: Memory needed ' . $memory . ' + ' . $InUse . ' (in use) = ' . ($memory + $InUse) . ' Limit:' . ini_get('memory_limit'));
   //Try to set it
   ini_set('memory_limit',$memory + $InUse);
debug('After: Limit ' . ini_get('memory_limit'));
}


Last edited by jbudd on 23. Sep 2009, 11:06, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: 23. Sep 2009, 11:06 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
Thanks,

This looks really good.
I will include this change in the next build and will add this to TWG for the next version then as well.

- Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
powered by phpbb | Datenschutz/ Privacy policy