ID: 51056
Updated by: [email protected]
Reported By: [email protected]
Status: Feedback
Bug Type: Streams related
Operating System: Linux Gentoo 2.6.32
PHP Version: 5.3.1
New Comment:
While for file sockets it makes sense when reading data to make sure a
buffer gets completly filled until EOF is reached, this is not true
for sockets.
There is already a condition for "greedy read", but it does not apply
when we first restore data from the read buffer.
Here is a diff (PHP_5_3) that solves the issue:
Index: main/streams/streams.c
===================================================================
--- main/streams/streams.c (révision 295152)
+++ main/streams/streams.c (copie de travail)
@@ -592,6 +592,10 @@
size -= toread;
buf += toread;
didread += toread;
+
+ /* avoid trying to read if we already have
data to pass */
+ if (stream->wrapper !=
&php_plain_files_wrapper)
+ break;
}
/* ignore eof here; the underlying state might have
changed */
Test script output:
Testing PHP version: 5.3.3-dev
fread took 0.07ms to read 8 bytes
fread took 5.07ms to read 256 bytes
fread took 0.00ms to read 45 bytes
fread took 1000.11ms to read 8 bytes
fread took 5.02ms to read 256 bytes
fread took 0.00ms to read 45 bytes
fread took 1000.13ms to read 8 bytes
fread took 5.04ms to read 256 bytes
Previous Comments:
------------------------------------------------------------------------
[2010-02-16 13:06:45] [email protected]
I tried to switch to non-blocking mode. This solves this issue with
most sockets, except for SSL sockets when transmitting a lot of data.
This bug is blocking in my case (socket communication transmitting a
lot of data).
------------------------------------------------------------------------
[2010-02-16 12:19:38] [email protected]
Testing PHP version: 5.2.13RC3-dev
fread took 0.04ms to read 8 bytes
fread took 4.88ms to read 256 bytes
fread took 1000.04ms to read 53 bytes
fread took 4.96ms to read 256 bytes
fread took 1000.06ms to read 53 bytes
fread took 4.97ms to read 256 bytes
fread took 1000.06ms to read 53 bytes
(etc)
------------------------------------------------------------------------
[2010-02-16 12:00:52] [email protected]
Confirmed with PHP_5_3
Testing PHP version: 5.3.3-dev
fread took 0.07ms to read 8 bytes
fread took 5.06ms to read 256 bytes
fread took 1000.10ms to read 53 bytes
fread took 5.03ms to read 256 bytes
fread took 1000.11ms to read 53 bytes
fread took 5.04ms to read 256 bytes
fread took 1000.10ms to read 53 bytes
I'll need a bit more time for PHP_5_2 as flex-2.5.4 is becoming more
difficult to find.
------------------------------------------------------------------------
[2010-02-16 11:11:54] [email protected]
This report looks a bit like bug #50856 (about non-blocking mode), but
it seems to be related to a different part of the streams api (non
blocking mode, fopen wrapper for http, while I'm testing on sockets in
blocking mode).
I'm about to test with vanilla PHP_5_2 and PHP_5_3 from svn (once
compilation completes). In the meantime I could reproduce the problem
on PHP 5.2.12 (gentoo patched version).
------------------------------------------------------------------------
[2010-02-16 10:56:46] [email protected]
Isn't this same (or related) as bug #50856 is? Does it happen with
PHP_5_2 ? And I'd guess you have tested latest PHP_5_3 as well?
------------------------------------------------------------------------
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
http://bugs.php.net/51056
--
Edit this bug report at http://bugs.php.net/?id=51056&edit=1