Edit report at https://bugs.php.net/bug.php?id=60817&edit=1

 ID:                 60817
 Updated by:         s...@php.net
 Reported by:        landeholm at gmail dot com
 Summary:            stream_get_line() incorrectly blocks
-Status:             Closed
+Status:             Re-Opened
 Type:               Bug
 Package:            Streams related
 Operating System:   Linux/Ubuntu
 PHP Version:        5.3.9
 Assigned To:        cataphract
 Block user comment: N
 Private report:     N

 New Comment:

Re-opened to track 5.4. Please merge to 5.4 and close.


Previous Comments:
------------------------------------------------------------------------
[2012-01-22 20:57:19] cataphr...@php.net

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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Fixed, now the function doesn't try to fill the buffer with $length bytes; it 
behaves more like fgets() typically returning false in the last iteration (if 
the 
file ends with the delimiter).

------------------------------------------------------------------------
[2012-01-22 20:30:38] cataphr...@php.net

Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=322582
Log: - Further fix for bug #60455 (stream_get_line misbehaves if EOF is not 
detected
  together with the last read).
- Fixed bug #60817 (stream_get_line() reads from stream even when there is
  already sufficient data buffered). stream_get_line() now behaves more like
  fgets(), as is documented.
#withheld commit to 5.4

------------------------------------------------------------------------
[2012-01-20 11:56:03] landeholm at gmail dot com

Oops, the expected result should be:

server got line: test #1
server got line: test2
server got line: test3
server got line: test4
server done
client done

------------------------------------------------------------------------
[2012-01-20 11:55:10] landeholm at gmail dot com

Description:
------------
stream_get_line() will block even though data has been received and there are 
lines ready to be parsed in php's internal buffer. 

It makes it impossible for example to implement a blocking HTTP server as the 
server will only parse the first line in the HTTP request and then both the 
server and client will hang as both are waiting for more data.

Test script:
---------------
$c = pcntl_fork();
if ($c > 0) {
$socket = stream_socket_server("tcp://127.0.0.1:10000");
$socket2 = stream_socket_accept($socket);
while (!feof($socket2))
print "server got line: " . stream_get_line($socket2, 1024, "\r\n") . "\n";
print "server done\n";
} else {
sleep(1);
$socket = stream_socket_client("tcp://127.0.0.1:10000");
fwrite($socket, "test #1\r\ntest2\r\ntest3\r\ntest4\r\n");
fread($socket, 1000);
print "client done\n";
}
die(0);


Expected result:
----------------
client done
server got line: test #1
server got line: test2
server got line: test3
server got line: test4
server done

Actual result:
--------------
server got line: test #1



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60817&edit=1

Reply via email to