Doc->Req #61168 [Opn]: fwrite() should allow for buffering
| From: | cmb@php.net | Date: | Fri, 01 Jul 2016 21:14:38 +0000 |
| Subject: | Doc->Req #61168 [Opn]: fwrite() should allow for buffering | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201978@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61168&edit=1
ID: 61168
Updated by: cmb@php.net
Reported by: tstarling@php.net
-Summary: fwrite() has no buffering
+Summary: fwrite() should allow for buffering
Status: Open
-Type: Documentation Problem
+Type: Feature/Change Request
Package: Streams related
Operating System: Linux
PHP Version: 5.4.0RC8
Block user comment: N
Private report: N
New Comment:
I've fixed the docs; changing to feature request as indicated by
Gustavo.
Previous Comments:
------------------------------------------------------------------------
[2016-07-01 21:13:01] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=339538
Log: Address #61168: fwrite() has no buffering
The info that fwrite() is normally buffered is obviously wrong, but the
rest of the paragraph also looks fishy, so we remove it altogether.
------------------------------------------------------------------------
[2013-04-22 18:41:34] rasmus@php.net
You are right, it isn't. In fact you can easily do it. Go to http://edit.php.net
and make the change and submit it.
------------------------------------------------------------------------
[2013-04-22 01:02:52] tstarling@php.net
Still not even a documentation change? It's been more than a year, and I can't imagine it
being particularly complex to edit a single sentence in the manual.
------------------------------------------------------------------------
[2012-02-23 14:49:03] cataphract@php.net
Perhaps this change in plain_wrapper.c would be a good idea:
@@ -583,7 +583,13 @@
case PHP_STREAM_OPTION_WRITE_BUFFER:
if (data->file == NULL) {
- return -1;
+ char fixed_mode[5];
+ php_stream_mode_sanitize_fdopen_fopencookie(stream, fixed_mode);
+ data->file = fdopen(data->fd, fixed_mode);
+ if (data->file == NULL) {
+ return -1;
+ }
+ data->fd = -1;
}
if (ptrparam)
I'll have to think a bit more about the implications.
------------------------------------------------------------------------
[2012-02-23 10:32:05] cataphract@php.net
You're not checking the return value of stream_set_write_buffer. If you were, you'd have
noticed it returns -1 indicating failure.
PHP does not have buffering for writes as it does for reads. In fact, it has the opposite: it breaks
the data to write in chunk_size bits (see the undocumented stream_set_chunk_size in PHP 5.4).
Therefore, streams that want to provide write buffering must do so themselves; PHP merely provides a
way to configure the write buffering. In the case of plain files, write buffering is supported, but
only for stdio files, not plain file descriptors. The stream by default doesn't use stdio (to
avoid duplication of read buffers for instance).
Extensions can open a FILE* and pass it to php_stream_fopen_from_file(), but it seems that this
won't suffice because PHP will still use low-level I/O on the file descriptor returned by
fileno(), so you'd have to violate some abstractions and zero the fd field in the
php_stdio_stream_data structure (stored in stream->abstract) to force stdio to be used. This
should be revisited.
In any case, the documentation is wrong. I'm changing this to a documentation problem for the
time being.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61168
--
Edit this bug report at https://bugs.php.net/bug.php?id=61168&edit=1