#35090 [NEW]: file i/o is not buffered
| From: | askalski at gmail dot com | Date: | Thu, 03 Nov 2005 18:16:10 +0000 |
| Subject: | #35090 [NEW]: file i/o is not buffered | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-87490@lists.php.net to get a copy of this message | ||
From: askalski at gmail dot com
Operating system: linux
PHP version: 5CVS-2005-11-03 (snap)
PHP Bug Type: Filesystem function related
Bug description: file i/o is not buffered
Description:
------------
The documentation for stream_set_write_buffer() says that fwrite()s are
buffered at 8K by default. In reality, it does not buffer at all. Any
attempt to call stream_set_write_buffer() on a regular file handle results
in failure.
Reproduce code:
---------------
$fh = fopen("asdf", "w");
// write some data using the default buffering
for ($i = 0; $i < 5; $i++)
fwrite($fh, "test");
// demonstrate that stream_set_write_buffer fails
$n = stream_set_write_buffer($fh, 8192);
if ($n != 0)
echo "stream_set_write_buffer failed\n";
// write some more data to demonstrate the failure
for ($i = 0; $i < 5; $i++)
fwrite($fh, "again");
fclose($fh);
Expected result:
----------------
PHP should buffer its I/O, and strace should log a single write().
stream_set_write_buffer() should not fail on regular files.
Actual result:
--------------
Output:
stream_set_write_buffer failed
Abridged strace output:
open("/tmp/php5-200511031730/asdf", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
write(3, "test", 4) = 4
write(3, "test", 4) = 4
write(3, "test", 4) = 4
write(3, "test", 4) = 4
write(3, "test", 4) = 4
write(1, "stream_set_write_buffer failed\n", 31) = 31
write(3, "again", 5) = 5
write(3, "again", 5) = 5
write(3, "again", 5) = 5
write(3, "again", 5) = 5
write(3, "again", 5) = 5
close(3) = 0
--
Edit bug report at http://bugs.php.net/?id=35090&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35090&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35090&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35090&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35090&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35090&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35090&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35090&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35090&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35090&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35090&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35090&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35090&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35090&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35090&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35090&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35090&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35090&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35090&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35090&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35090&r=mysqlcfg