简体   繁体   English

在php中处理大型压缩文件

[英]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. 我正在使用pclzip库,压缩文件的大小可以在250MB-750MB之间。

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? 您是否尝试过在脚本中使用set_time_limit ( int $seconds )

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. 这应该将您压缩的每10个文件的max_execution_time重置为30秒。

Maybe 10 is a little small a number but you get the idea. 也许10有点小,但您知道了。

Alternatively you could try setting the max_execution_time to 0 like so, just once at the top of this script. 另外,您可以尝试将max_execution_time设置为0,就像这样,仅在此脚本的顶部一次。

set_time_limit( 0 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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