PHP 输出流过滤器 w/zlib.inflate 创建空白文件


PHP Output Stream Filter w/zlib.inflate creates blank file

我正在尝试在与ftp_fget()一起使用的文件指针上使用内置的流过滤器"zlib.inflate"。 这个想法是,如果文件被 gzip 压缩,这将膨胀它。 在我附加流过滤器之前,一切都有效。

    $local = $remote = 'whatever.txt';
    # Create local file to transfer ftp file into
    $localFile = fopen($local, 'w');
    # Attach inflation stream filter with write filter, so we can inflate as we write to the new file
    stream_filter_append($localFile, 'zlib.inflate', STREAM_FILTER_WRITE);
    # Use fget to read remote file into local with optional inflation
    # $this->_connection(); returns csv resource
    $result    = ftp_fget($this->_connection(), $localFile, $remote, FTP_BINARY);

这似乎应该是一件非常简单的事情,但它只是给了我一个空白文件。 有什么想法吗?

[编辑] 在 Debian Lenny 上运行 PHP 5.2.6。 Zlib 已安装并显示在 phpinfo() 下

[编辑2] 看来这与此错误有关。 https://bugs.php.net/bug.php?id=49411 如果是这样,我将关闭它。

[编辑 3] 使用 PHP 5.4.4 启动一个 Vb 实例,我仍然遇到同样的问题,所以我认为这不是一个错误。

这是我对流如何工作的误解。 它们不支持命令行 gzip 实用程序将使用的相同标头和尾部。(开头为 2 个字节,末尾为校验和)。 我将不得不从不同的角度来攻击这个问题。 我将把它标记为已解决。