Abhay Shukla
Abhay Shukla

Reputation: 33

Handling large compressed file in php

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

Upvotes: 1

Views: 445

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94682

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 );

Upvotes: 1

Related Questions