2 stream_get_line() on non-blocking stream
5 $sockets = @stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
6 if (!$sockets) die("skip stream_socket_pair() should work");
13 * Tests that stream_get_line() behaves as documented on non-blocking streams:
14 * Never return incomplete lines, except on documented conditions:
15 * length bytes have been read, the string specified by ending is found, EOF.
18 $sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
21 stream_set_blocking($sockets[1], 0);
25 fwrite($sockets[0], b"line start");
26 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
27 var_dump(stream_get_line($sockets[1], 8192, $eol));
28 fwrite($sockets[0], b", line end");
29 fwrite($sockets[0], b", $eol");
30 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns full line (EOL found)
31 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Nothing to read
32 var_dump(stream_get_line($sockets[1], 8192, $eol));
34 fwrite($sockets[0], b"incomplete line");
35 var_dump(stream_get_line($sockets[1], strlen(b"incomplete line"), $eol)); // EOL not found but $length has been read, return incomplete line
37 fwrite($sockets[0], b"incomplete line");
38 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
39 var_dump(fread($sockets[1], strlen(b"incomplete line"))); // Returns buffer readden by stream_get_line
41 fwrite($sockets[0], b"end of file");
42 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Does not returns incomplete line (EOL not found)
45 var_dump(stream_get_line($sockets[1], 8192, $eol)); // Returns incomplete line (End of file)
53 resource(%d) of type (stream)
55 resource(%d) of type (stream)
59 string(22) "line start, line end, "
62 string(15) "incomplete line"
64 string(15) "incomplete line"
66 string(11) "end of file"