简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM