php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48596 stream_filter_remove() example code does not work
Submitted: 2009-06-18 14:49 UTC Modified: 2009-11-28 14:54 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php_nospam at ramihyn dot sytes dot net Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.*, 6CVS (2009-07-17) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php_nospam at ramihyn dot sytes dot net
New email:
PHP Version: OS:

 

 [2009-06-18 14:49 UTC] php_nospam at ramihyn dot sytes dot net
Description:
------------
The example provided for stream_filter_remove() does not work as expected.

Reproduce code:
---------------
<?php
$fp = fopen("test.txt", "w");

$rot13_filter = stream_filter_append($fp, "string.rot13", STREAM_FILTER_WRITE);
fwrite($fp, "This is ");
stream_filter_remove($rot13_filter);
fwrite($fp, "a test\n");

rewind($fp);
fpassthru($fp);
fclose($fp);

?>

Expected result:
----------------
Guvf vf a test

Actual result:
--------------
(no output)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-18 14:54 UTC] php_nospam at ramihyn dot sytes dot net
Also there seems to be a problem with other filters: the below example hangs at fread(), if the script rewind()s the stream.

If closing the file and opening a new file handle, everyhing works as expected.

<?php
$str = "The quick brown fox jumps over the lazy dog.";

$fp = fopen("test.bin","w");

$bz_filter = stream_filter_append($fp,"bzip2.compress",9);
fwrite($fp,$str,strlen($str));
stream_filter_remove($bz_filter);

#fclose($fp);
#fopen($fp,"test.bin","r+");
rewind($fp);

$bz_filter = stream_filter_append($fp,"bzip2.decompress");
$str2 = fread($fp,strlen($str));
stream_filter_remove($bz_filter);

fclose($fp);

var_dump($str2);
?>
 [2009-06-18 17:52 UTC] php_nospam at ramihyn dot sytes dot net
If using the bzip2.compress or zlib.deflate filters, ftell() returns the same value as before using the filter to write to the stream:

<?php
$s = "The quick brown fox jumps over the lazy dog.";
$fp = fopen("test.bin","w");
fwrite($fp,$s);
var_dump(ftell($fp)); // int(44)
$filter = stream_filter_append($fp,"zlib.deflate",STREAM_FILTER_WRITE,9);
fwrite($fp,$s);
stream_filter_remove($filter);
var_dump(ftell($fp)); // int(44)
fclose($fp);
?>
 [2009-06-20 21:56 UTC] majkl578 at gmail dot com
Same problem as in first post here (code tested).
OS: Debian Lenny (unstable)
Same PHP version.
 [2009-06-20 21:57 UTC] majkl578 at gmail dot com
Sorry, not same, I have 5.3.0RC4
 [2009-06-21 00:26 UTC] php_nospam at ramihyn dot sytes dot net
Still doesn't work for me with RC4.
 [2009-06-23 11:25 UTC] pajoye@php.net
Is it windows specific?
 [2009-06-23 18:10 UTC] php_nospam at ramihyn dot sytes dot net
The example code for stream_filter_remove() doesn't run on my Linux VM either, which i compiled 5.3.0RC4 on. Same result as on my Windows box: it correctly writes to the "test.txt" file what it should, but fpassthru() doesnt output anything.

Doesn't seem to be windows specific.
 [2009-06-23 19:53 UTC] php_nospam at ramihyn dot sytes dot net
Had to recompile PHP because i didn't have zlib and bzip2 included, but now i've also tested the other pieces of code on the Linux VM.
Same result as on the Windows box.

Using filters seems to corrupt the file handle somehow:
After using a compression filter to write to a file, ftell() returns the same value as before appending the filter, but it is still possible to write to the file.

After using a decompression filter to read from a file, ftell() returns the same value as before appending the filter, but every call to fread() returns an empty string.

In addition, if the script first reads something from the stream, then a decompression filter is appended for reading and the script tries to read something, i get the following warning:

Warning: stream_filter_append(): Filter failed to process pre-buffered data in .../test.php on line 11

Is it, somehow, possible to have the buffers flushed in that case?
 [2009-07-09 20:25 UTC] jani@php.net
Does this happen with PHP 5.2.10 and 5.2.9 ?
 [2009-07-15 02:38 UTC] php_nospam at ramihyn dot sytes dot net
Yes, for all pieces of code specified in this bug report, and PHP version 5.2.10; i do not have PHP 5.2.9 anymore, the download server too, so i can't tell about 5.2.9
 [2009-07-16 18:21 UTC] php_nospam at ramihyn dot sytes dot net
The scripts show the same behaviour in PHP 5.2.6
 [2009-11-28 14:54 UTC] pierrick@php.net
In the reproduce code, the file pointer is open for write only. I tested the same code with the file pointer open for read/write and it worked as expected on 5.2.11 and 5.3.1
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 05:01:26 2019 UTC