From:
Operating system: Linux
PHP version: Irrelevant
Package: Streams related
Bug Type: Bug
Bug description:stream_set_read_buffer() not working as expected
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 bug report at http://bugs.php.net/bug.php?id=51854&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51854&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51854&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51854&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51854&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51854&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51854&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51854&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51854&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51854&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51854&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51854&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51854&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51854&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51854&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51854&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51854&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51854&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51854&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51854&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51854&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51854&r=mysqlcfg