1

I'm trying to compress many images at once in my server. The size of the compressed file can range from 250MB-750MB I'm using pclzip library.

I'm using shared hosting so max execution time and memory limit is limited. How can i solve this problem? or Please tell me about any alternative solutions.

Thanks

Abhay Shukla
  • 33
  • 1
  • 7
  • Perhaps these operations are simply too big to accomplish on a shared host. This is the reason that you have limitations on execution time and memory usage - you wouldn't want someone else's process to slow down your operations... – Lix Nov 06 '14 at 13:13
  • Perhaps try to compress the files incrementally and not all "at once". – Lix Nov 06 '14 at 13:13
  • yes, i tried to compress the files incrementally as you suggested i.e. multiple zip file instead of just one big zip file. But in that case also the max_execution_time of the script exceeds my server limit of 30sec. – Abhay Shukla Nov 06 '14 at 13:17
  • I meant adding one image to the zip file each time instead of adding multiple files at once. – Lix Nov 06 '14 at 13:19
  • yes, did it, but script fails in max_execution_time. Do you have any suggestion like- 1. hosting the application to dedicated/virtual server 2. Deploying the app in other shared host where i can increase the max_execution_time of the script. – Abhay Shukla Nov 06 '14 at 13:24

1 Answers1

1

Have you tried using set_time_limit ( int $seconds ) within your script?

Excuse the pseudo code but something like this

initialise the zip class

foreach ( files in the directory as $idx => $name) {
    add $name to the zip file;

    // every 10 files zipped, reset the max_execution_time
    if ( $idx > 0 && $idx % 10 == 0 ) {
        set_time_limit ( 30 );
    }
}

This should keep resetting the max_execution_time to 30 seconds every 10 files you zip.

Maybe 10 is a little small a number but you get the idea.

Alternatively you could try setting the max_execution_time to 0 like so, just once at the top of this script.

set_time_limit( 0 );
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • Thanks, i allready tried as you suggested. But the problem is when i contacted the support team of my host they said i can not change/alter any of their default value. What do you suggest in this scenerio? Is it better to go for other hosts where i can set those values or use dedicated/virtual server instead? – Abhay Shukla Nov 06 '14 at 13:49