简体   繁体   English

PHP ZipArchive extractTo()停滞了大文件

[英]PHP ZipArchive extractTo() stalls with large files

I am working on a script that uses the extractTo method of ZipArchive to unzip some pretty large files (some are over 10G). 我正在使用ZipArchive的extractTo方法解压缩一些非常大的文件(某些超过10G)的脚本。 Everything works fine for small files, but I have been testing it with files that are ~4G and noticed that unzip works up to a point, then it stops actually unzipping. 对于小文件,一切都可以正常工作,但是我一直在使用〜4G的文件进行测试,并注意到解压缩可以工作到一定程度,然后实际上停止了解压缩。 However, the PHP script appears to be running. 但是,PHP脚本似乎正在运行。 No errors or exceptions are thrown. 没有抛出错误或异常。 From a terminal I sit in the folder and keep typing ls -la to watch the size of the extracted file grow. 在终端上,我坐在文件夹中,然后继续输入ls -la来观看提取文件的大小。 It does so for a while, then stops and the script continues to load (watching via browser and via top). 它会执行一会儿,然后停止并继续加载脚本(通过浏览器和顶部观看)。 The script will then run for the specified timeout period (I set to 3600) and throw a time-out error. 然后,脚本将在指定的超时时间(我设置为3600)内运行,并引发超时错误。 The box is running Centos 6.6, 16G of RAM, plenty of processing power, and plenty of disc space. 该机器运行Centos 6.6、16G RAM,足够的处理能力和足够的磁盘空间。 Seems to be crashing at 5011800064 bytes unzipped. 似乎在5011800064字节解压缩时崩溃。 Here are some select bits of my code: 这是我的代码的一些选择位:

set_time_limit(1200);
ini_set('memory_limit', '1024M');

$zip = new ZipArchive;

    $res = $zip->open($zipPath);

    if ($res === TRUE)
    {
        $extres = $zip->extractTo(
            $unzipPath, 
            $filesToExtract
        );

        $zip->close();
    }

Any help would be greatly appreciated. 任何帮助将不胜感激。 I am also curious to know if the extractTo() function tries to load the whole zip into memory? 我也很好奇,知道extractTo()函数是否尝试将整个zip加载到内存中? I have scoured the PHP documentation and cannot find anything relevant. 我已经搜索过PHP文档,找不到任何相关的内容。 All of the related posts either do not have answers and were not specific in their explanation of the problem. 所有相关职位都没有答案,也没有具体说明问题。

Edit: Just to confirm, I have over 20G free and setting different memory limits for the script doesn't change the number of bytes unzipped. 编辑:只是为了确认,我有超过20G的可用空间,并且为脚本设置不同的内存限制不会改变解压缩的字节数。

Update: I have scoured httpd.conf, php.ini, and cannot find any settings that are prohibiting the unzip operations from working. 更新:我已经搜索了httpd.conf,php.ini,并且找不到任何禁止解压缩操作的设置。

A traditional .zip archive is limited in size to 4GB : 传统的.zip归档文件的大小限制为4GB

The maximum size for both the archive file and the individual files inside it is 4,294,967,295 bytes (232−1 bytes, or 4 GiB minus 1 byte) for standard .ZIP, and 18,446,744,073,709,551,615 bytes (264−1 bytes, or 16 EiB minus 1 byte) for ZIP64. 对于标准.ZIP,存档文件和其中的单个文件的最大大小为4,294,967,295字节(232-1字节或4 GiB减去1字节),以及18,446,744,073,709,551,615字节(264-1字节或16 EiB减去1字节) )的ZIP64。

To decompress larger archives using ZIP64 in PHP, you'll need to use PHP 5.6 that uses libzip 0.11.2 . 要在PHP中使用ZIP64解压缩较大的档案,您需要使用使用libzip 0.11.2的 PHP 5.6

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

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