note 94505 modified in function.fopen by danbrown

From: Date: Thu, 12 Nov 2009 21:28:46 +0000
Subject: note 94505 modified in function.fopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162828@lists.php.net to get a copy of this message
Take great care if you project to use both ftp and compression wrapper within fopened stream to remotely write a compressed file built on the fly. This code : <?php $resFile = fopen('compress.bzip2://./test.rnd.bz2', 'wb'); for ($i=0; $i < 1000000 ; $i++) { fwrite($resFile, chr(rand(255))); } fclose($resFile); ?> will produce a well formed bz2 compressed random content file. <?php $resFile = fopen('compress.bzip2://ftp://ftp.example.com/test.rnd.bz2', 'wb'); for ($i=0; $i < 1000000 ; $i++) { fwrite($resFile, chr(rand(255))); } fclose($resFile); ?> will produce a corrupted bz2 compressed random content file. The file is not really corrupted, it is incomplete. The tail of the file is not written to the stream, the file is truncated at the end of complete compressed data block. Adding fflush($resFile); before closing the file does not fix this issue. This problem can be reproduced with PHP 5.2.6 (bundled with Debian 2.6.26-13lenny2) and may be related to http://bugs.php.net/bug.php?id=42117. --was-- Take great care if you project to use both ftp and compression wrapper within fopened stream to remotely write a compressed file built on the fly. This code : <?php $resFile = fopen('compress.bzip2://./test.rnd.bz2', 'wb'); for ($i=0; $i < 1000000 ; $i++) { fwrite($resFile, chr(rand(255))); } close($resFile); ?> will produce a well formed bz2 compressed random content file. <?php $resFile = fopen('compress.bzip2://ftp://ftp.example.com/test.rnd.bz2', 'wb'); for ($i=0; $i < 1000000 ; $i++) { fwrite($resFile, chr(rand(255))); } close($resFile); ?> will produce a corrupted bz2 compressed random content file. The file is not really corrupted, it is incomplete. The tail of the file is not written to the stream, the file is truncated at the end of complete compressed data block. Adding fflush($resFile); before closing the file does not fix this issue. This problem can be reproduced with PHP 5.2.6 (bundled with Debian 2.6.26-13lenny2) and may be related to http://bugs.php.net/bug.php?id=42117. http://php.net/manual/en/function.fopen.php

« previous php.notes (#162828) next »