我正在尝试在我的服务器中一次压缩许多图像。压缩文件的大小范围为 250MB-750MB 我使用的是 pclzip 库。
我正在使用共享主机,因此最大执行时间和内存限制是有限的。我怎么解决这个问题?或请告诉我任何替代解决方案。
谢谢
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 );