php - 使用 php 在 gzopen 中解压缩大型 gzip 文件的缓冲区大小是多少?

标签 php gzip internal-server-error compression

function uncompress($srcName, $dstName) {
    $sfp = gzopen($srcName, "rb");
    $dstName = str_replace('.gz', '', $dstName);
    $fp = fopen($dstName, "w");

        fseek($FileOpen, -4, SEEK_END);
        $buf = fread($FileOpen, 4);
        $GZFileSize = end(unpack("V", $buf));

    while ($string = gzread($sfp, $GZFileSize)) {
        fwrite($fp, $string, strlen($string));
    }
    gzclose($sfp);
    fclose($fp);
}

我使用这段代码进行解压缩,但它不起作用,并且出现以下错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

最佳答案

这个函数看起来很粗略。看来您正在用户区重新实现 stream_copy_to_stream()。忘掉缓冲区,只使用原生的东西。

function uncompress($srcName, $dstName)
{
    $src = gzopen($srcName, 'rb');
    $dst = fopen($dstName, 'wb');

    stream_copy_to_stream($src, $dst);

    gzclose($src);
    fclose($dst);
}

想想看,您甚至可以使用 copy()

function uncompress($srcName, $dstName)
{
    copy('compress.zlib://' . $srcName, $dstName);
}

关于php - 使用 php 在 gzopen 中解压缩大型 gzip 文件的缓冲区大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11267311/

相关文章:

PHP PDO MySql - 插入偶尔 undefined variable

php - 无法将 php 变量从 Controller 渲染到 yii2 中查看

php - 使用 PHP 下载图像时出现 500 内部服务器错误

php - CakePHP 2.0 上的服务器内部错误 500

iis-7 - 带有 IIS 日志的内部服务器错误 500

非标准字符的 PHP 过滤器

php - 添加到购物车时,将产品当前选定的变体 SKU 值获取到像素数据层中

node.js - 使用 zlib 压缩多个文件

java - Java中解压PHP的gzcompress

python - 使用 python 在 Heroku 上启用压缩