From:             
Operating system: Linux/Ubuntu
PHP version:      5.3.9
Package:          Streams related
Bug Type:         Bug
Bug description:stream_get_line() incorrectly blocks

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 bug report at https://bugs.php.net/bug.php?id=60817&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60817&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60817&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60817&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60817&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60817&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60817&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60817&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60817&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60817&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60817&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60817&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60817&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60817&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60817&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60817&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60817&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60817&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60817&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60817&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60817&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60817&r=mysqlcfg

Reply via email to