Edit report at http://bugs.php.net/bug.php?id=51854&edit=1

 ID:               51854
 Updated by:       paj...@php.net
 Reported by:      datib...@php.net
 Summary:          stream_set_read_buffer() not working as expected
-Status:           Open
+Status:           Closed
 Type:             Bug
 Package:          Streams related
-Operating System: Linux
+Operating System: *
 PHP Version:      Irrelevant
-Assigned To:      
+Assigned To:      pajoye

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2010-05-18 21:39:41] paj...@php.net

Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=299466
Log: - #51854, fix logic (patch by Tjerk)

------------------------------------------------------------------------
[2010-05-18 19:57:36] datib...@php.net

Description:
------------
Recently, the stream_set_read_buffer() was introduced; it's signature
suggests that a buffer size can be set.



However, when passing any non-zero value, the stream becomes
unbuffered.



This is because of a missing check inside _php_stream_set_option():



if (value == PHP_STREAM_BUFFER_NONE) {

    stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;

} else {

    stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER;

}

Test script:
---------------
<?php



$f = fopen('/dev/urandom', 'rb');

// setting read buffer to 1024

stream_set_read_buffer($f, 1024);

// reading the first 10 bytes

$s = fread($f, 10);

fclose($f);



/*

========= STRACE OUTPUT =========



open("/dev/urandom", O_RDONLY)          = 3

fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0

lseek(3, 0, SEEK_CUR)                   = 0

read(3, "\3X\264\rQ\277\273\367\347Z", 10) = 10

close(3)                                = 0

*/

?>

Expected result:
----------------
Either the read() loads 1024 bytes, which would be ideal, or it should
still load the default buffer size (8192 bytes).



The attached patch addresses the latter behaviour.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51854&edit=1

Reply via email to