|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50787 stream_set_write_buffer() has no effect on socket streams
Submitted: 2010-01-17 19:03 UTC Modified: 2011-02-19 02:43 UTC
From: vnegrier at optilian dot com Assigned: cataphract (profile)
Status: Closed Package: Streams related
PHP Version: 5.3.1 OS: linux
Private report: No CVE-ID: None
 [2010-01-17 19:03 UTC] vnegrier at optilian dot com
Socket streams do not implement the PHP_STREAM_OPTION_WRITE_BUFFER call, and the stream chunk size is always fixed at 8192 bytes.

This is not a problem with SOCK_STREAM type sockets, but with SOCK_DGRAM is breaks the datagrams if they are more than 8192 bytes (which is IMHO a bug).

Here is a patch against 5.3.1 to add support for stream_set_write_buffer() with socket streams:

--- main/streams/xp_socket.c.orig       2010-01-17 19:56:39.000000000 +0100
+++ main/streams/xp_socket.c    2010-01-17 19:59:34.000000000 +0100
@@ -266,6 +266,7 @@
        int oldmode, flags;
        php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
        php_stream_xport_param *xparam;
+       size_t size;

        switch(option) {
@@ -400,6 +401,14 @@
                                        return PHP_STREAM_OPTION_RETURN_NOTIMPL;

+               case PHP_STREAM_OPTION_WRITE_BUFFER:
+                       if (ptrparam)
+                               size = *(size_t *)ptrparam;
+                       else
+                               size = PHP_SOCK_CHUNK_SIZE;
+                       php_stream_set_chunk_size(stream, size);
+                       return PHP_STREAM_OPTION_RETURN_OK;
                        return PHP_STREAM_OPTION_RETURN_NOTIMPL;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-18 12:50 UTC]
Automatic comment from SVN on behalf of iliaa
Log: Fixed bug #50787 (stream_set_write_buffer() has no effect on socket streams).
 [2010-01-18 12:50 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2010-02-03 20:21 UTC]
Automatic comment from SVN on behalf of pajoye
Log: - Fixed bug #50787 (stream_set_write_buffer() has no effect on socket streams).
 [2011-02-16 18:33 UTC]
-Status: Closed +Status: Re-Opened -Assigned To: +Assigned To: cataphract
 [2011-02-16 18:33 UTC]
I'm reopening this because the fix makes the meaning of PHP_STREAM_OPTION_WRITE_BUFFER ambiguous.

For the plain wrapper it's used as a wrapper for setvbuf and the only values it accepts are 0, 1 and 2, for _IOFBF, _IOLBF and _IONBF.

For the socket stream, it's being used as a synonymous of PHP_STREAM_OPTION_SET_CHUNK_SIZE. This makes no sense, especially since the chunk size is also used for read buffering.

I understand the problem, but this can't be the solution; I'm reverting this patch since setvbuf is specific to the stdio, but not without a solution first -- perhaps a new function to change the chunk size.
 [2011-02-16 18:43 UTC]
Just a few more comments:

Strangely, PHP_STREAM_OPTION_WRITE_BUFFER also controls the flag PHP_STREAM_FLAG_NO_BUFFER, which is used only for reading (controls whether to keep a PHP read buffer or not), which is also a target of PHP_STREAM_OPTION_READ_BUFFER. So there's already some mixing of read and write semantics in PHP_STREAM_OPTION_WRITE_BUFFER.

In any case, I still think this should be revisited.
 [2011-02-19 02:43 UTC]
-Status: Re-Opened +Status: Closed
 [2011-02-19 02:43 UTC]
Fixed in trunk by reverting the patch attached to this bug report and adding a stream_set_chunk_size function, PHP 5.3 is unaffected.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Dec 10 23:01:27 2023 UTC