#35090 [Opn->Asn]: file i/o is not buffered

From: Date: Thu, 03 Nov 2005 20:29:08 +0000
Subject: #35090 [Opn->Asn]: file i/o is not buffered
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-87502@lists.php.net to get a copy of this message
ID: 35090 Updated by: derick@php.net Reported By: askalski at gmail dot com -Status: Open +Status: Assigned Bug Type: Filesystem function related Operating System: linux PHP Version: 5CVS-2005-11-03 (snap) -Assigned To: +Assigned To: wez New Comment: Can you please answer why this is not a bug Wez? I forgot the reason :) Previous Comments: ------------------------------------------------------------------------ [2005-11-03 19:16:09] askalski at gmail dot com 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 this bug report at http://bugs.php.net/?id=35090&edit=1

« previous php.bugs (#87502) next »