What is suitable buffer size for uncompressing large gzip files in gzopen using php?

坚强是说给别人听的谎言 提交于 2019-12-06 07:38:33

This should help you see the error messages. Either it will displayed on the screen or will be printed into the txt file, although the directory must be writable by php.

<?php //top of script
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', 'errors.txt');

This function looks sketchy. It seems you're reimplementing stream_copy_to_stream() in userland. Forget about buffers and simply use the native stuff.

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

    stream_copy_to_stream($src, $dst);

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

Come to think of it, you could probably even use copy()

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

I changed my function to this and my problem was solved :

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


            $GZFileSize = filesize($srcName);


        while ($string = gzread($sfp, $GZFileSize)) {
            fwrite($fp, $string, strlen($string));
        }
        gzclose($sfp);
        fclose($fp);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!