Bug #61168 [NEW]: fwrite() has no buffering
| From: | tstarling@php.net | Date: | Thu, 23 Feb 2012 06:16:10 +0000 |
| Subject: | Bug #61168 [NEW]: fwrite() has no buffering | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-167748@lists.php.net to get a copy of this message | ||
From: tstarling
Operating system: Linux
PHP version: 5.4.0RC8
Package: Streams related
Bug Type: Bug
Bug description:fwrite() has no buffering
Description:
------------
The stream_set_write_buffer() manual entry indicates that fwrite() buffers
its output. This is incorrect. For regular files, no buffering is ever
done, each fwrite() call leads to a syscall.
This is a performance issue, especially for extensions like the CDB handler
in DBA. I have a real-world script that uses almost as much system CPU as
user CPU, because each dba_insert() call leads to multiple syscalls.
Test script:
---------------
$f = fopen( '/tmp/blah', 'w' );
stream_set_write_buffer( $f, 8192 );
for ( $i = 0; $i < 10; $i++ ) {
fwrite( $f, 'x' );
}
fclose( $f );
Expected result:
----------------
strace php write-tight-loop.php
...
write(3, "xxxxxxxxxx", 1) = 10
...
Actual result:
--------------
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
write(3, "x", 1) = 1
--
Edit bug report at https://bugs.php.net/bug.php?id=61168&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61168&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61168&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61168&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=61168&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61168&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=61168&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=61168&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=61168&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=61168&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=61168&r=support
Expected behavior: https://bugs.php.net/fix.php?id=61168&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=61168&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=61168&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=61168&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61168&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61168&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=61168&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=61168&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=61168&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=61168&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=61168&r=mysqlcfg